Cortex Challenge Team / Mbed 2 deprecated Nucleo_read_analog_set

Dependencies:   mbed

Fork of Nucleo-Analog_read by Cortex Challenge Team

Revision:
0:242976b62902
Child:
1:dc5a274adc7d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 12 23:40:48 2015 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+
+#define voltage 3300
+#define mv1(x)       (x*voltage)
+#define mv2(x)       ((x*voltage)/0xFFFF)
+#define mv3(x)       (x*voltage)
+AnalogIn analog_value(A0);
+
+DigitalOut led(LED1);
+
+int main()
+{
+    float meas1;
+    int meas2;
+    float meas3;
+
+    printf("\nAnalogIn example\n");
+
+    while(1) {
+        meas1 = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+        meas1 = mv1(meas1); // Change the value to be in the 0 to 3300 range
+
+        meas2 = analog_value.read_u16(); // Converts and read the analog input value (value from 0.0 to 0xFFFF)
+        meas2 = mv2(meas2); // Change the value to be in the 0 to 3300 range
+
+        meas3 = analog_value; // Converts and read the analog input value (value from 0.0 to 1.0)
+        meas3 = mv3(meas3); // Change the value to be in the 0 to 3300 range
+        
+        printf("measure = %.0f mV, %d mV, %.0f mV\n", meas1,meas2,meas3);
+        if (meas1 > 2000 && meas2 > 2000 && meas3 > 2000) { // If the value is greater than 2V then switch the LED on
+            led = 1;
+        } else {
+            led = 0;
+        }
+        wait(0.2); // 200 ms
+    }
+}