blink an led

Dependencies:   mbed

Committer:
maclobdell
Date:
Mon May 09 19:47:06 2016 +0000
Revision:
0:232d11a32e07
Child:
1:c14fc6db8e1f
initial version - modified from https://github.com/janjongboom/sxsw

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:232d11a32e07 1 #include "mbed.h" // this tells us to load mbed related functions
maclobdell 0:232d11a32e07 2
maclobdell 0:232d11a32e07 3 DigitalOut red(LED_RED); // we create a variable 'red', use it as an out port
maclobdell 0:232d11a32e07 4 Ticker flipper; //Ticker = recurring interrupt to repeatedly call a function at a specified rate
maclobdell 0:232d11a32e07 5
maclobdell 0:232d11a32e07 6 void flip() {
maclobdell 0:232d11a32e07 7 red = !red;
maclobdell 0:232d11a32e07 8 }
maclobdell 0:232d11a32e07 9
maclobdell 0:232d11a32e07 10 // YOUR CODE HERE
maclobdell 0:232d11a32e07 11
maclobdell 0:232d11a32e07 12 // this code runs when the microcontroller starts up
maclobdell 0:232d11a32e07 13 int main() {
maclobdell 0:232d11a32e07 14 red = 1; //turn the led off, (1=off, I know it's weird)
maclobdell 0:232d11a32e07 15
maclobdell 0:232d11a32e07 16 // we want to blink an led, every 500 ms.
maclobdell 0:232d11a32e07 17 flipper.attach(&flip, 0.5); // the address of the function to be attached (flip) and the interval (in seconds)
maclobdell 0:232d11a32e07 18
maclobdell 0:232d11a32e07 19 // spin in a main loop. flipper will interrupt it to call flip
maclobdell 0:232d11a32e07 20 while(1) {}
maclobdell 0:232d11a32e07 21 }