Lab 3: Tommy Maly and Corwin Stites / Mbed 2 deprecated lab2programb

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tmaly45
Date:
Wed Sep 26 00:41:15 2018 +0000
Parent:
0:09571003fc2e
Commit message:
Updated 9-25

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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. 
    
 
 }