First trail ADC to receive one value

Dependencies:   mbed

Revision:
0:4833c37bb5b3
diff -r 000000000000 -r 4833c37bb5b3 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 19 02:03:24 2018 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+Serial pc(USBTX, USBRX);
+I2C i2c(D0, D1);
+ 
+int main()
+    {
+       uint8_t curr_addr;
+       char data[1],vdata[2];
+       float voltage, input;
+       curr_addr = 0x92;
+       data[0]=0x02; /*selecting AIN2 for PCF 8591 to read from*/
+       i2c.start();
+       i2c.write(curr_addr,data,1); 
+    
+    while(1)
+    {
+            vdata[0] = 0;
+            i2c.read(curr_addr,vdata,1);
+            wait(0.3);
+            input=vdata[0];
+            voltage=(input/256)*5;
+            //pc.printf("%f\r\n", input);
+            pc.printf("the voltage is %f\r\n",voltage);
+    }
+}
\ No newline at end of file