CA 2.3 Original Code

Dependencies:   mbed

Committer:
vmg
Date:
Sun Jul 26 20:57:22 2020 +0000
Revision:
0:6855a1935929
CA 2.3 Original Code

Who changed what in which revision?

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