Debouncing

Dependencies:   mbed C12832

Committer:
mariana_batalim
Date:
Sat Jun 20 10:35:02 2020 +0000
Revision:
0:6b510cf92f81
Child:
1:73ef4330603a
T00215868_Interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariana_batalim 0:6b510cf92f81 1 #include "mbed.h"
mariana_batalim 0:6b510cf92f81 2 #include "C12832.h"
mariana_batalim 0:6b510cf92f81 3 C12832 lcd(p5, p7, p6, p8, p11);
mariana_batalim 0:6b510cf92f81 4 InterruptIn joystickcenter(p14);
mariana_batalim 0:6b510cf92f81 5 InterruptIn button(p9);
mariana_batalim 0:6b510cf92f81 6 DigitalOut led(LED1);
mariana_batalim 0:6b510cf92f81 7 DigitalOut flash(LED4);
mariana_batalim 0:6b510cf92f81 8 Timer debounce;
mariana_batalim 0:6b510cf92f81 9 int x;
mariana_batalim 0:6b510cf92f81 10
mariana_batalim 0:6b510cf92f81 11 void flip() {
mariana_batalim 0:6b510cf92f81 12 debounce.start(); /* Start debounce timer */
mariana_batalim 0:6b510cf92f81 13 if (debounce.read_ms()>=3000)
mariana_batalim 0:6b510cf92f81 14 { led = !led; // toggles the led when the joystick button is pressed.
mariana_batalim 0:6b510cf92f81 15 x=1;
mariana_batalim 0:6b510cf92f81 16 }
mariana_batalim 0:6b510cf92f81 17 }
mariana_batalim 0:6b510cf92f81 18 int main() {
mariana_batalim 0:6b510cf92f81 19 joystickcenter.rise(&flip); // attach the function address to the rising edge
mariana_batalim 0:6b510cf92f81 20 button.mode(PullUp); // With this, no external pullup resistor needed
mariana_batalim 0:6b510cf92f81 21 button.rise(&flip); // attach the function address to the rising edge
mariana_batalim 0:6b510cf92f81 22 while(1) { // wait around, interrupts will interrupt this!
mariana_batalim 0:6b510cf92f81 23 flash = !flash; // turns LED4 on if off, off if on
mariana_batalim 0:6b510cf92f81 24 if (x ==1)
mariana_batalim 0:6b510cf92f81 25 {
mariana_batalim 0:6b510cf92f81 26 lcd.printf("Test ");
mariana_batalim 0:6b510cf92f81 27 x=0;
mariana_batalim 0:6b510cf92f81 28 }
mariana_batalim 0:6b510cf92f81 29 wait(0.25); // the instruction to wait for a quarter-second
mariana_batalim 0:6b510cf92f81 30 }
mariana_batalim 0:6b510cf92f81 31 }