T00221592 Winter Lab1 Interrupt Code

Dependencies:   mbed C12832

Committer:
t00221592
Date:
Tue Dec 21 10:02:49 2021 +0000
Revision:
0:a5b3abcdc569
Winter Lab1

Who changed what in which revision?

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