Mac Lobdell
/
1_blinky
for testing
Fork of 1_blinky by
main.cpp@1:641d32f7b4ec, 2016-05-10 (annotated)
- Committer:
- maclobski
- Date:
- Tue May 10 03:31:21 2016 +0000
- Revision:
- 1:641d32f7b4ec
- Parent:
- 0:232d11a32e07
for testing
Who changed what in which revision?
User | Revision | Line number | New 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 | |
maclobski | 1:641d32f7b4ec | 6 | // YOUR CODE HERE |
maclobski | 1:641d32f7b4ec | 7 | |
maclobski | 1:641d32f7b4ec | 8 | //REMOVE |
maclobski | 1:641d32f7b4ec | 9 | static void blinky() { |
maclobski | 1:641d32f7b4ec | 10 | // the LED is either on or off (a 1 or a 0). We can inverse the value with the `!` (inverse operator). |
maclobski | 1:641d32f7b4ec | 11 | // the flipped value is what we write back to the LED, thus toggling the LED. |
maclobdell | 0:232d11a32e07 | 12 | red = !red; |
maclobdell | 0:232d11a32e07 | 13 | } |
maclobski | 1:641d32f7b4ec | 14 | //END_REMOVE |
maclobdell | 0:232d11a32e07 | 15 | |
maclobdell | 0:232d11a32e07 | 16 | // this code runs when the microcontroller starts up |
maclobdell | 0:232d11a32e07 | 17 | int main() { |
maclobdell | 0:232d11a32e07 | 18 | red = 1; //turn the led off, (1=off, I know it's weird) |
maclobdell | 0:232d11a32e07 | 19 | |
maclobdell | 0:232d11a32e07 | 20 | // we want to blink an led, every 500 ms. |
maclobski | 1:641d32f7b4ec | 21 | flipper.attach(&blinky, 0.5); // the address of the function to be attached (flip) and the interval (in seconds) |
maclobdell | 0:232d11a32e07 | 22 | |
maclobdell | 0:232d11a32e07 | 23 | // spin in a main loop. flipper will interrupt it to call flip |
maclobdell | 0:232d11a32e07 | 24 | while(1) {} |
maclobdell | 0:232d11a32e07 | 25 | } |