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.
Dependencies: mbed
Fork of Arrays by
main.cpp@0:1c6fbef51567, 2017-08-12 (annotated)
- Committer:
- rossatmsoe
- Date:
- Sat Aug 12 21:12:14 2017 +0000
- Revision:
- 0:1c6fbef51567
Initial version of Arrays program for MSOE EE2905
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rossatmsoe | 0:1c6fbef51567 | 1 | #include "mbed.h" |
| rossatmsoe | 0:1c6fbef51567 | 2 | |
| rossatmsoe | 0:1c6fbef51567 | 3 | /* |
| rossatmsoe | 0:1c6fbef51567 | 4 | Arrays |
| rossatmsoe | 0:1c6fbef51567 | 5 | |
| rossatmsoe | 0:1c6fbef51567 | 6 | Demonstrates the use of an array to hold pin numbers |
| rossatmsoe | 0:1c6fbef51567 | 7 | in order to iterate over the pins in a sequence. |
| rossatmsoe | 0:1c6fbef51567 | 8 | Lights multiple LEDs in non-contiguous sequence, then in reverse. |
| rossatmsoe | 0:1c6fbef51567 | 9 | |
| rossatmsoe | 0:1c6fbef51567 | 10 | The circuit: |
| rossatmsoe | 0:1c6fbef51567 | 11 | * LEDs from pins 2 through 11 to ground |
| rossatmsoe | 0:1c6fbef51567 | 12 | |
| rossatmsoe | 0:1c6fbef51567 | 13 | created 2006 |
| rossatmsoe | 0:1c6fbef51567 | 14 | by David A. Mellis |
| rossatmsoe | 0:1c6fbef51567 | 15 | modified 30 Aug 2011 |
| rossatmsoe | 0:1c6fbef51567 | 16 | by Tom Igoe |
| rossatmsoe | 0:1c6fbef51567 | 17 | modified for Nucleo / mbed 12 Aug 2017 |
| rossatmsoe | 0:1c6fbef51567 | 18 | by Sheila Ross |
| rossatmsoe | 0:1c6fbef51567 | 19 | |
| rossatmsoe | 0:1c6fbef51567 | 20 | This example code is in the public domain. |
| rossatmsoe | 0:1c6fbef51567 | 21 | |
| rossatmsoe | 0:1c6fbef51567 | 22 | http://www.arduino.cc/en/Tutorial/Array |
| rossatmsoe | 0:1c6fbef51567 | 23 | */ |
| rossatmsoe | 0:1c6fbef51567 | 24 | |
| rossatmsoe | 0:1c6fbef51567 | 25 | float timer = 0.2; // The higher the number, the slower the timing. |
| rossatmsoe | 0:1c6fbef51567 | 26 | int position[] = { // an array of pin numbers to which LEDs are attached |
| rossatmsoe | 0:1c6fbef51567 | 27 | 2, 7, 4, 6, 5, 3, 9, 1, 0, 8 }; |
| rossatmsoe | 0:1c6fbef51567 | 28 | int pinCount = 10; // the number of pins (i.e. the length of the array) |
| rossatmsoe | 0:1c6fbef51567 | 29 | |
| rossatmsoe | 0:1c6fbef51567 | 30 | BusOut bar_graph(D2,D3,D4,D5,D6,D7,D8,D9,D10,D11); |
| rossatmsoe | 0:1c6fbef51567 | 31 | |
| rossatmsoe | 0:1c6fbef51567 | 32 | int main() { |
| rossatmsoe | 0:1c6fbef51567 | 33 | |
| rossatmsoe | 0:1c6fbef51567 | 34 | while(1) { // keep the lights going forever |
| rossatmsoe | 0:1c6fbef51567 | 35 | |
| rossatmsoe | 0:1c6fbef51567 | 36 | |
| rossatmsoe | 0:1c6fbef51567 | 37 | for(int n=0; n<pinCount; n++) { |
| rossatmsoe | 0:1c6fbef51567 | 38 | |
| rossatmsoe | 0:1c6fbef51567 | 39 | // Output a 1 shifted over "position" places |
| rossatmsoe | 0:1c6fbef51567 | 40 | // for the various values of "position" |
| rossatmsoe | 0:1c6fbef51567 | 41 | |
| rossatmsoe | 0:1c6fbef51567 | 42 | bar_graph = (1<<position[n]); |
| rossatmsoe | 0:1c6fbef51567 | 43 | |
| rossatmsoe | 0:1c6fbef51567 | 44 | wait(timer); |
| rossatmsoe | 0:1c6fbef51567 | 45 | } |
| rossatmsoe | 0:1c6fbef51567 | 46 | |
| rossatmsoe | 0:1c6fbef51567 | 47 | |
| rossatmsoe | 0:1c6fbef51567 | 48 | } |
| rossatmsoe | 0:1c6fbef51567 | 49 | |
| rossatmsoe | 0:1c6fbef51567 | 50 | } |
