Mac Lobdell / Mbed 2 deprecated 1_blinky

Dependencies:   mbed

Fork of 1_blinky by MakingMusicWorkshop

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"  // this tells us to load mbed related functions
00002 
00003 DigitalOut red(LED_RED);             // we create a variable 'red', use it as an out port
00004 Ticker flipper;   //Ticker = recurring interrupt to repeatedly call a function at a specified rate
00005 
00006 // YOUR CODE HERE
00007 
00008 //REMOVE
00009 static void blinky() {
00010     // the LED is either on or off (a 1 or a 0). We can inverse the value with the `!` (inverse operator).
00011     // the flipped value is what we write back to the LED, thus toggling the LED.
00012     red = !red;
00013 }
00014 //END_REMOVE
00015 
00016 // this code runs when the microcontroller starts up 
00017 int main() {
00018     red = 1;  //turn the led off, (1=off, I know it's weird)
00019     
00020     // we want to blink an led, every 500 ms.
00021     flipper.attach(&blinky, 0.5); // the address of the function to be attached (flip) and the interval (in seconds)
00022  
00023     // spin in a main loop. flipper will interrupt it to call flip
00024     while(1) {}
00025 }