5 ms·
You should try again. I think that code is verbose because of the borrowing and because you're trying to do a one-liner. I use the nrf-hal library with the nrf5
by gaganyaan 3y ago
You should try again. I think that code is verbose because of the borrowing and because you're trying to do a one-liner. I use the nrf-hal library with the nrf52840, and the code reads pretty nicely. Here's an example:
https://github.com/nrf-rs/nrf-hal/blob/master/examples/blinky-button-demo/src/main.rs https://github.com/nrf-rs/nrf-hal/blob/master/examples/blink...
- sophacles 3y agoIt reads like there's a bug in that example: loop { if button.is_high().unwrap() { led.set_high().unwrap(); } else { led.set_low().unwrap(); } } Wouldn't you want to call set_low when is_high is true? Also, woudn't the loop need a sleep to make the blinking be observable? this looks like it will be a roughly 50% pwm.
- gaganyaan 3y agoIt's checking to see if the button is high, not the led. "blinky" is a slightly misleading name. It doesn't cycle the led automatically, it turns the led on when you press a button It is a busy loop though, and in a real scenario you'd want to use interrupts instead of a loop like this.
- sophacles 3y agoOh wow, I read "button" as "blinker" in that code... Thanks for explaining it!