Alejandro Montes / Mbed 2 deprecated Experiment_3

Dependencies:   mbed C12832

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LAB_2.3.cpp Source File

LAB_2.3.cpp

00001 #include "mbed.h"
00002 #include "C12832.h"
00003 
00004 InterruptIn joystickcenter(p14);
00005 InterruptIn button(p9);
00006 DigitalOut led(LED1);
00007 DigitalOut flash(LED4);
00008 C12832 lcd(p5, p7, p6, p8, p11);
00009 int x;
00010 
00011 void flip() {
00012 x=1;
00013 led = !led; // toggles the led when the joystick button is pressed.
00014 }
00015 
00016 int main() {
00017     joystickcenter.rise(&flip);     // attach the function address to the rising edge
00018     button.mode(PullUp);            // With this, no external pullup resistor needed
00019     button.rise(&flip);             // attach the function address to the rising edge
00020         while(1) {                  // wait around, interrupts will interrupt this!
00021         flash = !flash;             // turns LED4 on if off, off if on
00022         wait(0.25);                 // the instruction to wait for a quarter-second 
00023             if(x==1){               //Check if the variable has been set and if so displays a message on the LCD
00024             lcd.locate(0,10);
00025             lcd.printf("Varialble SET!");
00026             wait(0.5);
00027             lcd.cls();              //Clears out the LCD
00028             x=0;                    //Set the variable back to 0
00029         }
00030     } 
00031 }