tomasz_gurajek

Dependencies:   mbed C12832

Committer:
t00204088
Date:
Sat Aug 01 12:06:44 2020 +0000
Revision:
0:a728181386a0
tomasz_gurajek;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t00204088 0:a728181386a0 1 #include "mbed.h"
t00204088 0:a728181386a0 2 #include "C12832.h" //library
t00204088 0:a728181386a0 3 C12832 lcd(p5,p6,p7,p8,p11);
t00204088 0:a728181386a0 4 InterruptIn joystickcenter(p14); // input joystic center pin 14
t00204088 0:a728181386a0 5 InterruptIn button(p9); // input button pin 9
t00204088 0:a728181386a0 6 DigitalOut led(LED1); // output LED 1
t00204088 0:a728181386a0 7 DigitalOut flash(LED4); // output LED 4
t00204088 0:a728181386a0 8 Timer debounce; //Timer class declaring the object call it debounce
t00204088 0:a728181386a0 9 int i;
t00204088 0:a728181386a0 10 void flip() //function
t00204088 0:a728181386a0 11 {
t00204088 0:a728181386a0 12 if (debounce.read_ms() > 5000) {//set timer to 5000ms
t00204088 0:a728181386a0 13 led = !led; // led on when the joystick button is pressed.
t00204088 0:a728181386a0 14 debounce.reset ();
t00204088 0:a728181386a0 15 i=1;
t00204088 0:a728181386a0 16 }
t00204088 0:a728181386a0 17 }
t00204088 0:a728181386a0 18 int main() {
t00204088 0:a728181386a0 19 joystickcenter.rise(&flip);// attach the function address to the rising edge
t00204088 0:a728181386a0 20 button.mode(PullUp); // With this, no external pullup resistor needed
t00204088 0:a728181386a0 21 button.rise(&flip); // attach the function address to the rising edge
t00204088 0:a728181386a0 22 debounce.start();
t00204088 0:a728181386a0 23 while(1) { // wait around, interrupts will interrupt this!
t00204088 0:a728181386a0 24 flash = !flash; // turns LED4 on if off, off if on
t00204088 0:a728181386a0 25 wait(0.5); // the instruction to wait for half-second
t00204088 0:a728181386a0 26 i=0;
t00204088 0:a728181386a0 27 if(i==1) {
t00204088 0:a728181386a0 28 lcd.locate(0,0);
t00204088 0:a728181386a0 29 lcd.printf("%d", debounce.read_ms()); //print on lcd debounce value
t00204088 0:a728181386a0 30 i=0;
t00204088 0:a728181386a0 31 }
t00204088 0:a728181386a0 32
t00204088 0:a728181386a0 33 }
t00204088 0:a728181386a0 34 }
t00204088 0:a728181386a0 35