Example using the user button on DISCO L475E IOT01, using interrupts

Dependencies:   mbed

Committer:
lmottola
Date:
Thu Nov 08 17:09:25 2018 +0000
Revision:
0:fc82b2d5fe07
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lmottola 0:fc82b2d5fe07 1 #include "mbed.h"
lmottola 0:fc82b2d5fe07 2
lmottola 0:fc82b2d5fe07 3 InterruptIn button(USER_BUTTON);
lmottola 0:fc82b2d5fe07 4 DigitalOut led(LED1);
lmottola 0:fc82b2d5fe07 5 DigitalOut heartbeat(LED2);
lmottola 0:fc82b2d5fe07 6
lmottola 0:fc82b2d5fe07 7 void toggle() {
lmottola 0:fc82b2d5fe07 8 led = !led;
lmottola 0:fc82b2d5fe07 9 }
lmottola 0:fc82b2d5fe07 10
lmottola 0:fc82b2d5fe07 11 int main() {
lmottola 0:fc82b2d5fe07 12 button.rise(&toggle); // Call toggle function on the rising edge
lmottola 0:fc82b2d5fe07 13 while(1) { // Wait around, interrupts will interrupt this!
lmottola 0:fc82b2d5fe07 14 heartbeat = !heartbeat;
lmottola 0:fc82b2d5fe07 15 wait(0.25);
lmottola 0:fc82b2d5fe07 16 }
lmottola 0:fc82b2d5fe07 17 }