Debouncing

Dependencies:   mbed C12832

Committer:
jforde
Date:
Tue Jul 28 11:52:58 2020 +0000
Revision:
1:73ef4330603a
Parent:
0:6b510cf92f81
Debouncing

Who changed what in which revision?

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