Stage-1 Students SoCEM / Mbed 2 deprecated Task422Solution

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Thu Sep 24 12:29:49 2015 +0000
Commit message:
Initial version 24-09-2015

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 6d9e82b27127 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 24 12:29:49 2015 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+
+#define kRED    (1 << 2)    //4
+#define kYELLOW (1 << 1)    //2
+#define kGREEN  (1 << 0)    //1
+
+//Global objects
+BusOut binaryOutput(D5, D6, D7);    
+DigitalIn SW1(D3);
+DigitalIn SW2(D4);
+
+AnalogIn POT_ADC_In(A0);
+AnalogIn LDD_ADC_In(A1);
+float fPOT, fLDR = 0.0;
+
+//Main function
+int main() {
+    
+    while(1) {
+        unsigned op = 0u;
+        
+        //Read ADC
+        fPOT = POT_ADC_In;  //Threshold
+        fLDR = LDD_ADC_In;  //Light reading
+        
+        //Write to terminal
+        printf("POT = %6.4f\tLDR = %6.4f\n", fPOT, fLDR);
+        
+        if (fLDR < 0.1f) {
+            op = kRED | kYELLOW | kGREEN;    
+        } else if (fLDR < 0.15f) {
+            op = kYELLOW | kRED;     
+        } else if (fLDR < 0.2f) {
+            op = kRED;
+        } else {
+            op = 0;    
+        }
+
+        //Write to port
+        binaryOutput = op;
+        
+        //Wait
+        wait(0.1);
+        
+    } //end while(1)
+} //end main
\ No newline at end of file
diff -r 000000000000 -r 6d9e82b27127 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 24 12:29:49 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81
\ No newline at end of file