Chris Byrne
/
TimerDebounce_Lab
TimerDebounce_Lab
Diff: main.cpp
- Revision:
- 1:4cc86a20ec45
- Parent:
- 0:6e4b35c64edd
diff -r 6e4b35c64edd -r 4cc86a20ec45 main.cpp --- a/main.cpp Fri Aug 07 09:50:24 2020 +0000 +++ b/main.cpp Fri Aug 07 15:41:54 2020 +0000 @@ -6,13 +6,14 @@ InterruptIn button(p9); DigitalOut led(LED1); DigitalOut flash(LED4); -Timer debounce; +Timer debounce; // define debounce timer int x; void flip(){ debounce.start(); - if (debounce.read_ms()>=5) { + if (debounce.read_ms()>=1000) { //by adjusting the timer up it + // ensures the function isn’t called too often. led = !led; // toggles the led when the joystick button is pressed. x=1; debounce.reset(); @@ -21,8 +22,6 @@ int main() { joystickcenter.rise(&flip); - // attach the function address to the rising edge button.mode(PullUp); - // With this, no external pullup resistor needed button.rise(&flip); // attach the function address to the rising edge while(1) { // wait around, interrupts will interrupt this! flash = !flash; // turns LED4 on if off, off if on