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.
main.cpp@0:293359e38af0, 2017-08-12 (annotated)
- Committer:
- rossatmsoe
- Date:
- Sat Aug 12 19:40:37 2017 +0000
- Revision:
- 0:293359e38af0
- Child:
- 1:9f6f3af9aaaa
Initial version of Blink for MSOE EE2905
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rossatmsoe | 0:293359e38af0 | 1 | /* |
rossatmsoe | 0:293359e38af0 | 2 | Blink |
rossatmsoe | 0:293359e38af0 | 3 | Turns on an LED on for one second, then off for one second, repeatedly. |
rossatmsoe | 0:293359e38af0 | 4 | |
rossatmsoe | 0:293359e38af0 | 5 | This example code is in the public domain. |
rossatmsoe | 0:293359e38af0 | 6 | */ |
rossatmsoe | 0:293359e38af0 | 7 | |
rossatmsoe | 0:293359e38af0 | 8 | // #include is a directive that "pastes" a file into your code. |
rossatmsoe | 0:293359e38af0 | 9 | // Use this specific #include at the beginning of each mbed program. |
rossatmsoe | 0:293359e38af0 | 10 | // mbed.h contains/points to the full definitions of our simple statements. |
rossatmsoe | 0:293359e38af0 | 11 | |
rossatmsoe | 0:293359e38af0 | 12 | #include "mbed.h" |
rossatmsoe | 0:293359e38af0 | 13 | |
rossatmsoe | 0:293359e38af0 | 14 | // Define the object board_LED to be a digital output connected to LED1, |
rossatmsoe | 0:293359e38af0 | 15 | // which is the little green LED on the Nucleo board. |
rossatmsoe | 0:293359e38af0 | 16 | |
rossatmsoe | 0:293359e38af0 | 17 | DigitalOut board_LED(LED1); |
rossatmsoe | 0:293359e38af0 | 18 | |
rossatmsoe | 0:293359e38af0 | 19 | /* The "main" function defines your main program--it executes as soon as |
rossatmsoe | 0:293359e38af0 | 20 | you program the board. |
rossatmsoe | 0:293359e38af0 | 21 | |
rossatmsoe | 0:293359e38af0 | 22 | Functions can return (compute and give back) a value. The main function |
rossatmsoe | 0:293359e38af0 | 23 | could return an integer error code, so it begins with int. |
rossatmsoe | 0:293359e38af0 | 24 | |
rossatmsoe | 0:293359e38af0 | 25 | Functions can also accept inputs. The main function cannot however, so |
rossatmsoe | 0:293359e38af0 | 26 | its round parentheses are empty. |
rossatmsoe | 0:293359e38af0 | 27 | */ |
rossatmsoe | 0:293359e38af0 | 28 | |
rossatmsoe | 0:293359e38af0 | 29 | int main() { // This curly brace marks the beginning of the main function. |
rossatmsoe | 0:293359e38af0 | 30 | |
rossatmsoe | 0:293359e38af0 | 31 | // while() will repeat a set of actions as long as the statement inside |
rossatmsoe | 0:293359e38af0 | 32 | // its round parentheses is true. 1 is the definition of true, so |
rossatmsoe | 0:293359e38af0 | 33 | // while(1) repeats forever. |
rossatmsoe | 0:293359e38af0 | 34 | |
rossatmsoe | 0:293359e38af0 | 35 | while(1) { // This curly brace marks the beginning of the repeated actions. |
rossatmsoe | 0:293359e38af0 | 36 | |
rossatmsoe | 0:293359e38af0 | 37 | board_LED = 1; // Turn on LED by storing a 1 in board_LED. |
rossatmsoe | 0:293359e38af0 | 38 | wait(0.5); // wait() will pause for a given number of seconds. |
rossatmsoe | 0:293359e38af0 | 39 | board_LED = 0; // Turn off LED by storing a 0 in board_LED. |
rossatmsoe | 0:293359e38af0 | 40 | wait(0.5); // wait another 1/2 second. |
rossatmsoe | 0:293359e38af0 | 41 | |
rossatmsoe | 0:293359e38af0 | 42 | } // end of repeated actions |
rossatmsoe | 0:293359e38af0 | 43 | |
rossatmsoe | 0:293359e38af0 | 44 | } // end of main function |