Lab 1 Program B

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mattsims12
Date:
Tue Sep 29 02:57:03 2015 +0000
Commit message:
Lab 1 Program B

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 3f29ab39579a main.cpp
--- /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
diff -r 000000000000 -r 3f29ab39579a mbed.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Tue Sep 29 02:57:03 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/screamer/code/mbed/#aff670d0d510