Christopher Wardlaw
/
ME21001_Lab02_Exercise_05
exercise 5
main.cpp@0:a95a52c376c2, 2016-09-24 (annotated)
- Committer:
- cwardlaw
- Date:
- Sat Sep 24 14:59:28 2016 +0000
- Revision:
- 0:a95a52c376c2
exercise 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cwardlaw | 0:a95a52c376c2 | 1 | /************************************************************** |
cwardlaw | 0:a95a52c376c2 | 2 | / Simple program program to show basic program structure |
cwardlaw | 0:a95a52c376c2 | 3 | / |
cwardlaw | 0:a95a52c376c2 | 4 | / The program simulates traffic lights. |
cwardlaw | 0:a95a52c376c2 | 5 | / |
cwardlaw | 0:a95a52c376c2 | 6 | /**************************************************************/ |
cwardlaw | 0:a95a52c376c2 | 7 | |
cwardlaw | 0:a95a52c376c2 | 8 | #include "mbed.h" |
cwardlaw | 0:a95a52c376c2 | 9 | |
cwardlaw | 0:a95a52c376c2 | 10 | DigitalOut yelLED(p22); // name attached LED p22 |
cwardlaw | 0:a95a52c376c2 | 11 | DigitalOut greLED(p24); // name attached LED p23 |
cwardlaw | 0:a95a52c376c2 | 12 | DigitalOut redLED(p23); // name attached LED p24 |
cwardlaw | 0:a95a52c376c2 | 13 | int main() { |
cwardlaw | 0:a95a52c376c2 | 14 | while(1) { // repeat indefinitely |
cwardlaw | 0:a95a52c376c2 | 15 | redLED = 1; // activates red LED |
cwardlaw | 0:a95a52c376c2 | 16 | wait(2); // pauses for 2 seconds |
cwardlaw | 0:a95a52c376c2 | 17 | yelLED = 1; // activates yellow LED |
cwardlaw | 0:a95a52c376c2 | 18 | wait(1); // pauses for a second |
cwardlaw | 0:a95a52c376c2 | 19 | redLED = 0; // deactivates red LED |
cwardlaw | 0:a95a52c376c2 | 20 | yelLED = 0; // deactivates yellow LED |
cwardlaw | 0:a95a52c376c2 | 21 | greLED = 1; // activates green LED |
cwardlaw | 0:a95a52c376c2 | 22 | wait(2); // pauses for 2 seconds |
cwardlaw | 0:a95a52c376c2 | 23 | greLED = 0; // deactivates green LED |
cwardlaw | 0:a95a52c376c2 | 24 | yelLED = 1; // activated yellow LED |
cwardlaw | 0:a95a52c376c2 | 25 | wait(1); // pauses for a second |
cwardlaw | 0:a95a52c376c2 | 26 | yelLED = 0; // deactivates yellow LED |
cwardlaw | 0:a95a52c376c2 | 27 | } |
cwardlaw | 0:a95a52c376c2 | 28 | } |