IT Tralee lab experiments

Dependencies:   mbed

Committer:
bmol
Date:
Sun Jul 26 13:30:47 2020 +0000
Revision:
0:5fb7a5f9f20b
IT Tralee;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bmol 0:5fb7a5f9f20b 1 #include "mbed.h"
bmol 0:5fb7a5f9f20b 2
bmol 0:5fb7a5f9f20b 3 InterruptIn joystickcenter(p14);
bmol 0:5fb7a5f9f20b 4 InterruptIn button(p9);
bmol 0:5fb7a5f9f20b 5 DigitalOut led(LED1);
bmol 0:5fb7a5f9f20b 6 DigitalOut flash(LED4);
bmol 0:5fb7a5f9f20b 7
bmol 0:5fb7a5f9f20b 8 void flip() {
bmol 0:5fb7a5f9f20b 9 led = !led; // toggles the led when the joystick button is pressed.
bmol 0:5fb7a5f9f20b 10 }
bmol 0:5fb7a5f9f20b 11 int main() {
bmol 0:5fb7a5f9f20b 12 joystickcenter.rise(&flip); // attach the function address to the rising edge
bmol 0:5fb7a5f9f20b 13 button.mode(PullUp); // With this, no external pullup resistor needed
bmol 0:5fb7a5f9f20b 14 button.rise(&flip); // attach the function address to the rising edge
bmol 0:5fb7a5f9f20b 15 while(1) { // wait around, interrupts will interrupt this!
bmol 0:5fb7a5f9f20b 16 flash = !flash; // turns LED4 on if off, off if on
bmol 0:5fb7a5f9f20b 17 wait(0.25); // the instruction to wait for a quarter-second
bmol 0:5fb7a5f9f20b 18 }
bmol 0:5fb7a5f9f20b 19 }
bmol 0:5fb7a5f9f20b 20
bmol 0:5fb7a5f9f20b 21
bmol 0:5fb7a5f9f20b 22