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@110:b148a36c9833, 2021-10-11 (annotated)
- Committer:
- CSTritt
- Date:
- Mon Oct 11 01:27:18 2021 +0000
- Revision:
- 110:b148a36c9833
- Parent:
- 108:eee3167b25b4
- Child:
- 111:459fa5199128
Initial Mbed v. 5 version (using sleep_for).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 107:61b9c99a4e27 | 1 | /* |
CSTritt | 110:b148a36c9833 | 2 | Project: ForLoopIteration |
CSTritt | 110:b148a36c9833 | 3 | File: main.cpp |
CSTritt | 110:b148a36c9833 | 4 | |
CSTritt | 110:b148a36c9833 | 5 | Demonstrates the use of a for() loop. Lights indivdiual LEDs of a bargraph |
CSTritt | 110:b148a36c9833 | 6 | display in sequence, then in reverse order. |
CSTritt | 110:b148a36c9833 | 7 | |
CSTritt | 110:b148a36c9833 | 8 | The circuit: |
CSTritt | 110:b148a36c9833 | 9 | |
CSTritt | 110:b148a36c9833 | 10 | Bargraph LEDs from pins D3 through D12 to ground via 330 Ohm resistors. |
CSTritt | 110:b148a36c9833 | 11 | |
CSTritt | 110:b148a36c9833 | 12 | Created 2006 by David A. Mellis |
CSTritt | 110:b148a36c9833 | 13 | Modified 2011 by Tom Igoe |
CSTritt | 110:b148a36c9833 | 14 | Modified for Nucleo / mbed 12 Aug 2017 by Sheila Ross |
CSTritt | 110:b148a36c9833 | 15 | Modified by C. S. Tritt 9/21/17 and 10/10/21 (v. 1.1, untested) |
CSTritt | 110:b148a36c9833 | 16 | |
CSTritt | 110:b148a36c9833 | 17 | This example code is in the public domain. |
CSTritt | 107:61b9c99a4e27 | 18 | */ |
CSTritt | 110:b148a36c9833 | 19 | |
Jonathan Austin |
0:2757d7abb7d9 | 20 | #include "mbed.h" |
CSTritt | 110:b148a36c9833 | 21 | |
CSTritt | 110:b148a36c9833 | 22 | const int DELAY = 100;; // mS wait time. |
CSTritt | 110:b148a36c9833 | 23 | |
CSTritt | 110:b148a36c9833 | 24 | BusOut bar_graph(D3,D4,D5,D6,D7,D8,D9,D10,D11,D12); |
CSTritt | 110:b148a36c9833 | 25 | |
CSTritt | 108:eee3167b25b4 | 26 | int main() { |
CSTritt | 110:b148a36c9833 | 27 | |
CSTritt | 110:b148a36c9833 | 28 | while(true) { // Keep the lights going back and forth forever. |
CSTritt | 110:b148a36c9833 | 29 | |
CSTritt | 110:b148a36c9833 | 30 | // Lighted bar will shift from 0 to 9 places. |
CSTritt | 110:b148a36c9833 | 31 | for(int shift = 0; shift < 10; shift++) { |
CSTritt | 110:b148a36c9833 | 32 | bar_graph = (1 << shift); // A 1 shifted over "shift" places. |
CSTritt | 110:b148a36c9833 | 33 | ThisThread::sleep_for(DELAY); // Pause |
CSTritt | 110:b148a36c9833 | 34 | } |
CSTritt | 110:b148a36c9833 | 35 | |
CSTritt | 110:b148a36c9833 | 36 | // Now shift down from 9 to 0 places. |
CSTritt | 110:b148a36c9833 | 37 | for(int shift = 9; shift >= 0; shift--) { |
CSTritt | 110:b148a36c9833 | 38 | bar_graph = (1 << shift); // A 1 shifted over "shift" places. |
CSTritt | 110:b148a36c9833 | 39 | ThisThread::sleep_for(DELAY); // Pause |
CSTritt | 108:eee3167b25b4 | 40 | } |
CSTritt | 108:eee3167b25b4 | 41 | } |
CSTritt | 108:eee3167b25b4 | 42 | } |