AUP_Lab1_GPIO

Dependencies:   mbed

Fork of Lab1_GPIO by 璇 李

Files at this revision

API Documentation at this revision

Comitter:
BrentLei
Date:
Thu Sep 17 05:44:49 2015 +0000
Parent:
0:55b07f83af75
Commit message:
Logic simplified

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 21 02:22:22 2015 +0000
+++ b/main.cpp	Thu Sep 17 05:44:49 2015 +0000
@@ -4,19 +4,22 @@
 DigitalOut blue(D8);
 DigitalOut green(D9);
 AnalogIn analog_value(A0);
-int i;
 
-int main() {
-    float meas;
-    int i;
+int main()
+{
+    double meas;
     
-    while(1) {
+    while(1)
+    {
         meas = analog_value.read();
         
-        i = (int)(meas * 8);
-        red = i & 1;
-        blue = i & 2;
-        green = i & 4;
-        wait(0.2);
+        if (meas < 0.3)
+            red = 0, blue = 1, green = 1;
+        else if (meas < 0.7)
+            red = 1, blue = 0, green = 1;
+        else
+            red = 1, blue = 1, green = 0;
+
+        wait(0.1);
     }
 }