Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 2_two_buttons by
main.cpp@1:83ad95149534, 2016-05-10 (annotated)
- Committer:
- maclobski
- Date:
- Tue May 10 15:12:12 2016 +0000
- Revision:
- 1:83ad95149534
- Parent:
- 0:49e04b14e729
for testing
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| maclobdell | 0:49e04b14e729 | 1 | #include "mbed.h" // this tells us to load mbed related functions | 
| maclobdell | 0:49e04b14e729 | 2 | |
| maclobdell | 0:49e04b14e729 | 3 | DigitalOut red(LED_RED); // we create a variable 'red', use it as an out port | 
| maclobdell | 0:49e04b14e729 | 4 | DigitalOut green(LED_GREEN); // we create a variable 'green', use it as an out port | 
| maclobdell | 0:49e04b14e729 | 5 | |
| maclobdell | 0:49e04b14e729 | 6 | InterruptIn btn2(SW2); // we create a variable 'btn2', use it as an in port | 
| maclobdell | 0:49e04b14e729 | 7 | InterruptIn btn3(SW3); // we create a variable 'btn3', use it as an in port | 
| maclobdell | 0:49e04b14e729 | 8 | |
| maclobdell | 0:49e04b14e729 | 9 | // YOUR CODE HERE | 
| maclobski | 1:83ad95149534 | 10 | //REMOVE | 
| maclobski | 1:83ad95149534 | 11 | static void toggle_red() { | 
| maclobski | 1:83ad95149534 | 12 | red = !red; | 
| maclobski | 1:83ad95149534 | 13 | } | 
| maclobski | 1:83ad95149534 | 14 | static void toggle_green() { | 
| maclobski | 1:83ad95149534 | 15 | green = !green; | 
| maclobski | 1:83ad95149534 | 16 | } | 
| maclobski | 1:83ad95149534 | 17 | //END REMOVE | 
| maclobdell | 0:49e04b14e729 | 18 | |
| maclobdell | 0:49e04b14e729 | 19 | // this code runs when the microcontroller starts up | 
| maclobdell | 0:49e04b14e729 | 20 | int main() { | 
| maclobdell | 0:49e04b14e729 | 21 | green = red = 1; // turn off green and red on startup (1=off, I know it's weird) | 
| maclobdell | 0:49e04b14e729 | 22 | |
| maclobdell | 0:49e04b14e729 | 23 | btn2.fall(toggle_red); | 
| maclobdell | 0:49e04b14e729 | 24 | btn3.fall(toggle_green); | 
| maclobdell | 0:49e04b14e729 | 25 | |
| maclobdell | 0:49e04b14e729 | 26 | // spin in a main loop. Wait for interrupts. | 
| maclobdell | 0:49e04b14e729 | 27 | while(1) {} | 
| maclobdell | 0:49e04b14e729 | 28 | } | 
