mech / Mbed OS AnalogIn_HelloWorld

Fork of AnalogIn_HelloWorld by mbed_example

Revision:
4:e29502420eef
Parent:
0:101a12a915c6
Child:
5:c22a0111045b
--- a/main.cpp	Mon Jun 26 09:10:45 2017 -0500
+++ b/main.cpp	Thu Nov 01 18:32:19 2018 +0000
@@ -17,8 +17,10 @@
 #include "mbed.h"
 
 // Initialize a pins to perform analog input and digital output fucntions
-AnalogIn   ain(A0);
-DigitalOut dout(LED1);
+AnalogIn   ain1(A1);
+AnalogIn   ain2(A2);
+AnalogIn   ain3(A3);
+DigitalOut dout(D1);
 
 int main(void)
 {
@@ -26,15 +28,14 @@
         // test the voltage on the initialized analog pin
         //  and if greater than 0.3 * VCC set the digital pin
         //  to a logic 1 otherwise a logic 0
-        if(ain > 0.3f) {
-            dout = 1;
-        } else {
-            dout = 0;
-        }
+        dout = 1;
         
         // print the percentage and 16 bit normalized values
-        printf("percentage: %3.3f%%\n", ain.read()*100.0f);
-        printf("normalized: 0x%04X \n", ain.read_u16());
-        wait(0.2f);
+       // printf("percentage: %3.3f%%\n", ain.read()*100.0f);
+       // printf("normalized: 0x%04X \n", ain.read_u16());
+        printf("voltage ain1:    %f V\n", ain1.read()*3.3f);
+        printf("voltage ain2:    %f V\n", ain2.read()*3.3f);
+        printf("voltage ain3:    %f V\n\n", ain3.read()*3.3f);
+        wait(2);
     }
 }