IT Tralee lab experiments

Dependencies:   mbed C12832

Committer:
bmol
Date:
Mon Aug 03 13:45:07 2020 +0000
Revision:
0:51746ad1e7a6
IT Tralee

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bmol 0:51746ad1e7a6 1 #include "mbed.h"
bmol 0:51746ad1e7a6 2 #include "C12832.h"
bmol 0:51746ad1e7a6 3
bmol 0:51746ad1e7a6 4 InterruptIn joystickcenter(p14);
bmol 0:51746ad1e7a6 5 InterruptIn button(p9);
bmol 0:51746ad1e7a6 6 DigitalOut led(LED1);
bmol 0:51746ad1e7a6 7 DigitalOut flash(LED4);
bmol 0:51746ad1e7a6 8 C12832 lcd(p5, p7, p6, p8, p11);
bmol 0:51746ad1e7a6 9
bmol 0:51746ad1e7a6 10 bool x;
bmol 0:51746ad1e7a6 11
bmol 0:51746ad1e7a6 12 void flip()
bmol 0:51746ad1e7a6 13
bmol 0:51746ad1e7a6 14 {
bmol 0:51746ad1e7a6 15 led = !led; // toggles the led when the joystick button is pressed.
bmol 0:51746ad1e7a6 16 }
bmol 0:51746ad1e7a6 17
bmol 0:51746ad1e7a6 18 int main()
bmol 0:51746ad1e7a6 19 {
bmol 0:51746ad1e7a6 20 joystickcenter.rise(&flip); // attach the function address to the rising edge
bmol 0:51746ad1e7a6 21 button.mode(PullUp); // With this, no external pullup resistor needed
bmol 0:51746ad1e7a6 22 button.rise(&flip); // attach the function address to the rising edge
bmol 0:51746ad1e7a6 23
bmol 0:51746ad1e7a6 24
bmol 0:51746ad1e7a6 25
bmol 0:51746ad1e7a6 26 while(1) { // wait around, interrupts will interrupt this!
bmol 0:51746ad1e7a6 27
bmol 0:51746ad1e7a6 28 if (x = led) {
bmol 0:51746ad1e7a6 29
bmol 0:51746ad1e7a6 30 lcd.cls();
bmol 0:51746ad1e7a6 31 lcd.locate(0,0);
bmol 0:51746ad1e7a6 32 lcd.printf("Led1 is ON");
bmol 0:51746ad1e7a6 33
bmol 0:51746ad1e7a6 34
bmol 0:51746ad1e7a6 35 }
bmol 0:51746ad1e7a6 36
bmol 0:51746ad1e7a6 37 else {
bmol 0:51746ad1e7a6 38 lcd.cls();
bmol 0:51746ad1e7a6 39 lcd.locate(0,0);
bmol 0:51746ad1e7a6 40 lcd.printf("Led1 is OFF");
bmol 0:51746ad1e7a6 41
bmol 0:51746ad1e7a6 42 }
bmol 0:51746ad1e7a6 43 flash = !flash; // turns LED4 on if off, off if on
bmol 0:51746ad1e7a6 44 wait(0.25); // the instruction to wait for a quarter-second
bmol 0:51746ad1e7a6 45
bmol 0:51746ad1e7a6 46 }
bmol 0:51746ad1e7a6 47 }