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

Dependencies:   mbed

main.cpp

Committer:
tmaly45
Date:
2018-09-26
Revision:
1:0a1e7d18b69c
Parent:
0:09571003fc2e

File content as of revision 1:0a1e7d18b69c:

//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}; // Sets an array of Digital Outputs that fall in line with the LEDs on the MBED. 



int main() {
    
    int i = 0; // initializes the integer i

    char enter_key; 
    
    Timer t; 
    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()); // Again, used to ensure randomness. Also prompts the user to start the light show. 

    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. 
   

}