main: improve button press detection
This commit is contained in:
parent
73a55e2a3f
commit
eb4e30f79a
4
main.c
4
main.c
|
@ -308,10 +308,10 @@ void main(void)
|
||||||
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
|
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
|
||||||
// handle button press
|
// handle button press
|
||||||
if (rw_button_pressed) {
|
if (rw_button_pressed) {
|
||||||
wait_10us(100); // wait 1 ms for the noise to be gone
|
wait_10us(10000); // wait 100 ms for the noise to be gone
|
||||||
|
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
|
||||||
if (0 == (RW_BUTTON_PORT->IDR.reg & RW_BUTTON_PIN)) { // ensure the button is pressed (the pull-up is really weak)
|
if (0 == (RW_BUTTON_PORT->IDR.reg & RW_BUTTON_PIN)) { // ensure the button is pressed (the pull-up is really weak)
|
||||||
run_led_off(); // clear RUN LED to see result at the end
|
run_led_off(); // clear RUN LED to see result at the end
|
||||||
wait_10us(10000); // debounce for 100 ms
|
|
||||||
uint8_t press_duration = 1; // start counting how long the button is pressed
|
uint8_t press_duration = 1; // start counting how long the button is pressed
|
||||||
while (0 == (RW_BUTTON_PORT->IDR.reg & RW_BUTTON_PIN)) { // wait until button is depressed
|
while (0 == (RW_BUTTON_PORT->IDR.reg & RW_BUTTON_PIN)) { // wait until button is depressed
|
||||||
wait_10us(10000); // wait for 100 ms
|
wait_10us(10000); // wait for 100 ms
|
||||||
|
|
Loading…
Reference in New Issue