report

Dependencies:   mbed

Committer:
GerRoche
Date:
Fri May 24 14:44:57 2019 +0000
Revision:
0:7ea89477d20f
lab 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GerRoche 0:7ea89477d20f 1 #include "mbed.h"
GerRoche 0:7ea89477d20f 2
GerRoche 0:7ea89477d20f 3 InterruptIn button(p5);
GerRoche 0:7ea89477d20f 4 DigitalOut led(LED1);
GerRoche 0:7ea89477d20f 5 DigitalOut flash(LED4);
GerRoche 0:7ea89477d20f 6
GerRoche 0:7ea89477d20f 7 void flip() {
GerRoche 0:7ea89477d20f 8 led = !led; // toggles the led, when pressing a button connects ground to p5.
GerRoche 0:7ea89477d20f 9 }
GerRoche 0:7ea89477d20f 10
GerRoche 0:7ea89477d20f 11 int main() {
GerRoche 0:7ea89477d20f 12 button.mode(PullUp); // with this command, no external pullup resistor needed
GerRoche 0:7ea89477d20f 13 button.rise(&flip); // attach the function address to the rising edge (of p5)
GerRoche 0:7ea89477d20f 14 while(1) { // wait around, interrupts will interrupt this!
GerRoche 0:7ea89477d20f 15 flash = !flash; // this just turns LED4 on and off every quarter-second
GerRoche 0:7ea89477d20f 16 wait(0.25); // this is the instruction to wait for a quarter-second
GerRoche 0:7ea89477d20f 17 }
GerRoche 0:7ea89477d20f 18 }