How to write stm32 to digitalpin

How to write stm32 to digitalpin using embassy-rs.

digitalWrite(R1_PIN, 50);

How to put value instead of just high & low?
Please help
Thanks

I don't understand your question. A single digital output can only be raised to a high level voltage or dropped to a low level (levels depend on technology, typically 0 and 3.3 volts or 0 and 5 volts). So high or low, or call it 1 and 0.

Basically it is a single bit. A single bit can only be in two possible states. So there there no way trying to write a value like 50 makes any sense. The value 50 needs at least 6 bits to represent it.

1 Like

Sorry for the confusion.

In arduino IDE i can write digitalWrite(PIN, 0) or digitalWrite(PIN, 255) or everything in between.

Is there any way to do so in embassy?

The thing is that the Arduino uses C++. In C and C++ boolean values are such that a zero value is "false" and any non-zero value is "true".

Of course in Rust that is not so. I know nothing of embassy but I presume that pin state parameter is of type bool or some enum. So you will have to do the conversion from whatever type you have to that yourself.

1 Like

Do what the Arduino libraries do for you in C or C++: map 0 to LOW and non-zero to HIGH.

As far as Arduino is concerned, digitalWrite(PIN, 0) is the same as digitalWrite(PIN, LOW). Everything else is the same as digitalWrite(PIN, HIGH), and the exact value is ignored.

1 Like

Thanks for the clarification. I was confuse between high-low & pwm.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.