First trail ADC to receive one value

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kwag
Date:
Mon Mar 19 02:03:24 2018 +0000
Commit message:
First test for to receive one value from the ADC;

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
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 19 02:03:24 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/aa5281ff4a02
\ No newline at end of file