Interrupt_2

Dependencies:   mbed C12832

Committer:
jforde
Date:
Tue Jul 28 11:50:35 2020 +0000
Revision:
2:0330a4b650d1
Parent:
1:61930fcd568c
Interrupt_2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jforde 2:0330a4b650d1 1 #include "mbed.h" //Preprocessor Directives
mariana_batalim 0:6b510cf92f81 2 #include "C12832.h"
jforde 2:0330a4b650d1 3
jforde 2:0330a4b650d1 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 int x;
mariana_batalim 0:6b510cf92f81 10
mariana_batalim 0:6b510cf92f81 11 void flip() {
jforde 2:0330a4b650d1 12 { led = !led; // toggles the led when the joystick button is pressed.
mariana_batalim 0:6b510cf92f81 13 x=1;
mariana_batalim 0:6b510cf92f81 14 }
mariana_batalim 0:6b510cf92f81 15 }
jforde 2:0330a4b650d1 16 int main() { //instructions in main () function
mariana_batalim 0:6b510cf92f81 17 joystickcenter.rise(&flip); // attach the function address to the rising edge
jforde 2:0330a4b650d1 18 button.mode(PullUp); // With this, no external pullup resistor needed
jforde 2:0330a4b650d1 19 button.rise(&flip); // attach the function address to the rising edge
jforde 2:0330a4b650d1 20 while(1) { // infinite loop, wait around, interrupts will interrupt this
jforde 2:0330a4b650d1 21 flash = !flash; // turns LED4 on if off, off if on
mariana_batalim 0:6b510cf92f81 22 if (x ==1)
mariana_batalim 0:6b510cf92f81 23 {
jforde 2:0330a4b650d1 24 lcd.locate (0,0);
jforde 2:0330a4b650d1 25 lcd.printf("Variable Is Set"); // Print out to LCD Display
mariana_batalim 0:6b510cf92f81 26 x=0;
mariana_batalim 0:6b510cf92f81 27 }
jforde 2:0330a4b650d1 28 wait(0.25); // the instruction to wait for a quarter-second
mariana_batalim 0:6b510cf92f81 29 }
mariana_batalim 0:6b510cf92f81 30 }