Stage-1 Students SoCEM / Mbed 2 deprecated Task431Solution

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Thu Sep 24 12:30:11 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 8f4002068b49 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 24 12:30:11 2015 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+
+//Global objects
+BusOut binaryOutput(D5, D6, D7);    
+AnalogIn POT_ADC_In(A0);
+AnalogIn LDD_ADC_In(A1);
+
+float fPOT, fLDR = 0.0;
+float fPOTAverage = 0.0, fLDRAverage = 0.0;
+unsigned int n = 0;
+unsigned int N = 10;
+
+//Main function
+int main() {
+    
+    while(1) {
+        
+        //Read ADC
+        fPOT = POT_ADC_In;
+        fLDR = LDD_ADC_In;
+        
+        //Calculate the average of both fPOT and fLDR
+        fPOTAverage += fPOT;
+        fLDRAverage += fLDR;
+        
+        //Update the sample count
+        n++;
+        
+        //Wait
+        wait(0.01);        
+        
+        //Do we have N samples?
+        if (n == N) {
+            
+            //Calculate average
+            fPOTAverage /= (float)N;
+            fLDRAverage /= (float)N;
+            
+            //Write to terminal
+            printf("POT = %6.4f\tLDR = %6.4f\n", fPOTAverage, fLDRAverage);
+        
+            //Check the threshold
+            if (fLDRAverage > fPOTAverage) {
+                binaryOutput = 0;   //Binary 000    
+            } else {
+                binaryOutput = 7;   //Binary 111
+            }  
+            
+            //RESET averages and sample count
+            n = 0;
+            fPOTAverage = 0.0;
+            fLDRAverage = 0.0;        
+        }
+
+        
+    } //end while(1)
+} //end main
\ No newline at end of file
diff -r 000000000000 -r 8f4002068b49 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 24 12:30:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad
\ No newline at end of file