Cleaner code

Dependencies:   mbed C12832

main.cpp

Committer:
ciaranom
Date:
2020-07-31
Revision:
2:d07750adfe89
Parent:
1:7149c0779e5b

File content as of revision 2:d07750adfe89:

#include "mbed.h"
#include "C12832.h"

InterruptIn joystickcenter(p14);
InterruptIn button(p9);
DigitalOut led(LED1);
DigitalOut flash(LED4);
C12832 lcd(p5, p7, p6, p8, p11);


int x=0; //sets variable x to 0


void flip() {
 led = !led; // toggles the led when the joystick button is pressed.
 x=1;  //  sets variable x to 1
}

void reset() //reset variable to 0
{
    x=0;
}

int main() {

 joystickcenter.rise(&flip); // attach the function address to the rising edge
 button.mode(PullUp); // With this, no external pullup resistor needed
 button.rise(&flip); // attach the function address to the rising edge
 

 
 while(1) { // wait around, interrupts will interrupt this!
 
  if (x==1){ //if variable 'x' is equivalent to 0
 lcd.locate(0,0); // Sets location on lcd to 0,0
 lcd.printf("Variable set to 1");  // Prints Variable set if loop parameter is true
 wait(10); //waits for 10 seconds, to show print on MBED lcd
 lcd.cls(); //clears lcd screen
 reset();;  //resets x to 0
 }
 
 
 flash = !flash; // turns LED4 on if off, off if on
 wait(0.25); // the instruction to wait for a quarter-second
 }
 }