Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:4cc86a20ec45, committed 2020-08-07
- Comitter:
- chbyrne79
- Date:
- Fri Aug 07 15:41:54 2020 +0000
- Parent:
- 0:6e4b35c64edd
- Commit message:
- TimerDebounce_Lab
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
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