![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
IT Tralee Life Long Learning 2020 Instrumentation, Monitoring and Control Module Laboratory Session
LAB_2.3.1.cpp@0:d13a1b0d344f, 2020-07-27 (annotated)
- Committer:
- alejandromontes
- Date:
- Mon Jul 27 20:23:56 2020 +0000
- Revision:
- 0:d13a1b0d344f
Alejandro Montes Instrumentation Monitoring and Control LAB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alejandromontes | 0:d13a1b0d344f | 1 | #include "mbed.h" |
alejandromontes | 0:d13a1b0d344f | 2 | #include "C12832.h" |
alejandromontes | 0:d13a1b0d344f | 3 | |
alejandromontes | 0:d13a1b0d344f | 4 | InterruptIn joystickcenter(p14); |
alejandromontes | 0:d13a1b0d344f | 5 | InterruptIn button(p9); |
alejandromontes | 0:d13a1b0d344f | 6 | DigitalOut led(LED1); |
alejandromontes | 0:d13a1b0d344f | 7 | DigitalOut flash(LED4); |
alejandromontes | 0:d13a1b0d344f | 8 | C12832 lcd(p5, p7, p6, p8, p11); |
alejandromontes | 0:d13a1b0d344f | 9 | int x; |
alejandromontes | 0:d13a1b0d344f | 10 | Timer debounce; |
alejandromontes | 0:d13a1b0d344f | 11 | float t=3000.0; |
alejandromontes | 0:d13a1b0d344f | 12 | |
alejandromontes | 0:d13a1b0d344f | 13 | void flip() { |
alejandromontes | 0:d13a1b0d344f | 14 | led = !led; // toggles the led when the joystick button is pressed. |
alejandromontes | 0:d13a1b0d344f | 15 | debounce.start(); // starts the timer the first time that the flip function is triggered. |
alejandromontes | 0:d13a1b0d344f | 16 | if (debounce.read_ms()>=t){ // compares the timer value to t |
alejandromontes | 0:d13a1b0d344f | 17 | x=1; // variable x set to 1 if the timer condition is met |
alejandromontes | 0:d13a1b0d344f | 18 | debounce.reset(); // reset the timer if the condition is met. |
alejandromontes | 0:d13a1b0d344f | 19 | } |
alejandromontes | 0:d13a1b0d344f | 20 | } |
alejandromontes | 0:d13a1b0d344f | 21 | |
alejandromontes | 0:d13a1b0d344f | 22 | int main() { |
alejandromontes | 0:d13a1b0d344f | 23 | |
alejandromontes | 0:d13a1b0d344f | 24 | joystickcenter.rise(&flip); // attach the function address to the rising edge |
alejandromontes | 0:d13a1b0d344f | 25 | button.mode(PullUp); // With this, no external pullup resistor needed |
alejandromontes | 0:d13a1b0d344f | 26 | button.rise(&flip); // attach the function address to the rising edge |
alejandromontes | 0:d13a1b0d344f | 27 | |
alejandromontes | 0:d13a1b0d344f | 28 | while(1) { // wait around, interrupts will interrupt this! |
alejandromontes | 0:d13a1b0d344f | 29 | flash = !flash; // turns LED4 on if off, off if on |
alejandromontes | 0:d13a1b0d344f | 30 | wait(0.25); // the instruction to wait for a quarter-second |
alejandromontes | 0:d13a1b0d344f | 31 | |
alejandromontes | 0:d13a1b0d344f | 32 | if(x==1){ // Check if the variable has been set and if so displays a message on the LCD |
alejandromontes | 0:d13a1b0d344f | 33 | lcd.locate(0,10); |
alejandromontes | 0:d13a1b0d344f | 34 | lcd.printf("Varialble SET!"); |
alejandromontes | 0:d13a1b0d344f | 35 | wait(0.5); |
alejandromontes | 0:d13a1b0d344f | 36 | lcd.cls(); //Clears out the LCD |
alejandromontes | 0:d13a1b0d344f | 37 | x=0; //Set the variable back to 0 |
alejandromontes | 0:d13a1b0d344f | 38 | } |
alejandromontes | 0:d13a1b0d344f | 39 | } |
alejandromontes | 0:d13a1b0d344f | 40 | } |