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
Diff: main.cpp
- Revision:
- 1:0a1e7d18b69c
- Parent:
- 0:09571003fc2e
diff -r 09571003fc2e -r 0a1e7d18b69c main.cpp
--- a/main.cpp Thu Sep 20 18:49:31 2018 +0000
+++ b/main.cpp Wed Sep 26 00:41:15 2018 +0000
@@ -1,30 +1,36 @@
+//Program B
+// This program randomly turns on a new LED every second.
+// Corey Stites & Tommy Maly
+
+
+
#include "mbed.h"
#include "time.h"
-DigitalOut myled[5] = {p25, p26, p27, p28, p29};
+DigitalOut myled[5] = {p25, p26, p27, p28, p29}; // Sets an array of Digital Outputs that fall in line with the LEDs on the MBED.
int main() {
- int i = 0;
+ int i = 0; // initializes the integer i
char enter_key;
Timer t;
- t.start();
+ t.start(); // The previous 3 lines were just to ensure randomness every time the program is ran.
printf("Ready?\n\r");
scanf("%c", &enter_key);
- srand(t.read_ms());
+ srand(t.read_ms()); // Again, used to ensure randomness. Also prompts the user to start the light show.
- while(1) {
- i = (rand()%4);
- myled[i] = 1;
- wait(1);
- myled[i] = 0;
- printf("%d\n\r", i);
- }
+ while(1) { // Starts the never-ending while-loop.
+ i = (rand()%4); // Sets i to be equal to a random integer between 0 and 4, the components for the 'myled' array.
+ myled[i] = 1; // Turns on the LED associated with the random integer generated in the step before.
+ wait(1); // Keeps it on for one second.
+ myled[i] = 0; // Turns off the LED associated with the random integer generated.
+ printf("%d\n\r", i); // Prints the integer created, in case you wanted to know.
+ } //This while loop will continue to generate a new integer 'i' and the part of the 'myled' array associated with that 'i' will turn on and off.
}