David Mc Sherry / Mbed 2 deprecated INS_LAB_Q3

Dependencies:   mbed C12832

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "C12832.h" // including lcd library
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 
00010 int var;    // declare a variable
00011  
00012 void flip() // Classes a flip function
00013 {
00014     var = 1; // Variable is high
00015     led = !led; // toggles the led when the joystick button is pressed.
00016 }
00017 int main()
00018 {
00019     joystickcenter.rise(&flip); //attach the function address to the rising edge
00020     button.mode(PullUp); // With this, no external pullup resistor needed
00021     button.rise(&flip); // attach the function address to the rising edge
00022     while(1) { // wait around, interrupts will interrupt this!
00023         flash = !flash; // turns LED4 on if off, off if on
00024         wait(0.25); // the instruction to wait for a quarter-second
00025         
00026         
00027         if (var == 1)   // Check if variable has been set 
00028         {
00029             lcd.locate(0,0); // print to LCD
00030             lcd.printf("The variable has been set");
00031             wait(3);
00032             lcd.cls();              // Clears LCD
00033             var=0;                    // Variable returns to low state
00034         }
00035     }
00036 }