Lab 1 Program B
Diff: main.cpp
- Revision:
- 0:3f29ab39579a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 29 02:57:03 2015 +0000 @@ -0,0 +1,38 @@ +/*Lab 1 Program B + Lights Random LED every second based on a timer's seed + Matthew Sims + Section 1001 +*/ + +#include "Timer.h" +#include "mbed.h" + +DigitalIn s1=p16; +DigitalOut out[]= {p26,p27,p28,p29,p30}; //Sets up pins +Timer timer; //Initializes timer object + +int main() +{ + + //Timer stopped by user to create a unique number for seed. + timer.start(); //starts timer + printf("Turn switch 1 on"); //prompt user to turn on switch. Only useful is terraterm is on + while(s1!=1) { //waits for user to turn on switch + if(s1==1) { //When switch 1 is on turned on, the timer stops + timer.stop(); //stops the timer + } + } + srand(timer.read_us()); //Sets up rand with a seed based on the timer's value + + int r=-1; + int prev=-1; + while(1) { //Infinite loop + while(r==prev) { //generates randoms until it is different from previously on random + r=rand()%5; //random int 0-4 based on seed + } + out[r]=1; //Turns on corresponding led + wait(1); + out[r]=0; + prev=r; //Wait 1 sec before repeating loop + } +} \ No newline at end of file