step 2

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
LanierUSNA16
Date:
Thu Sep 04 03:05:20 2014 +0000
Commit message:
step 2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r aeb4b85ccd83 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 04 03:05:20 2014 +0000
@@ -0,0 +1,53 @@
+
+#include "mbed.h"
+//Lab 2, part 2
+
+//code given by professor
+Serial pc(USBTX, USBRX);
+
+//Establish analog input on pin 20, called ain
+AnalogIn ain1(p20); 
+//create BusOut on MBED leds
+BusOut leds(LED1, LED2, LED3, LED4);
+//create float variable to store the analog voltage
+float signal1 = 0.0;
+
+int main()
+    {//begin main
+    
+        while(1)
+        {
+            //set computer sampling rate
+        pc.baud(921600);
+        //store the input analog voltage in the variable signal1
+        signal1 = ain1;
+        
+        if (signal1<=0.2)
+        {//if the analog input is less than 0.2, turn all the lights off
+            leds=0;  
+        }
+        
+        if((signal1>0.2) && (signal1<=0.4))
+        {//if the analog input is between 0.2 and 0.4, turn on only LED1
+            leds=1;   
+        }
+        
+        if((signal1>0.4) && (signal1<=0.6))
+        {//if the analog input is between 0.4 and 0.6, turn on LED1 and LED2
+            leds=3;   
+        }
+        if((signal1>0.6) && (signal1<=0.8))
+        {//if the analog input is between 0.6 and 0.8, turn on all lights, but LED4
+            leds=7;   
+        }
+        if((signal1>0.8) && (signal1<=1.0))
+        {//if the analog input is between 0.8 and 1.0, turn on all lights
+            leds=15;   
+        }
+        //print the input voltage to the Tera Term window, so we can double check the lights are turning on when they're supposed to
+        printf("%f\n", signal1);
+        //wait 0.5 seconds before running the loop again. Keeps the Tera Term window readable. 
+        wait(0.5);
+        }
+    
+    }//end main
\ No newline at end of file
diff -r 000000000000 -r aeb4b85ccd83 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 04 03:05:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file