test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
zero515
Date:
Sun Feb 05 15:35:18 2017 +0000
Commit message:
send

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	Sun Feb 05 15:35:18 2017 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+
+I2C i2c(D4, D5);
+Serial pc(USBTX, USBRX);
+
+int getDis()
+{
+    char data[2];
+    
+    data[0] = 0x00;
+    data[1] = 0x51;
+    int ack = i2c.write(0xE0,data,2);  
+    wait_ms(30);
+    
+    char reg = 0x02;   
+    ack = i2c.write(0xE0,&reg,1);  
+    ack = i2c.read(0xE1,data,2); 
+    return (data[0] << 8) | data[1];
+}
+
+int main() {
+pc.baud(115200);
+pc.printf("st\r\n");
+i2c.frequency(400000);
+ 
+   while(1) {
+
+       int dist = getDis();
+       pc.printf("%d\r\n",dist);
+       //wait_ms(50);
+
+   }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Feb 05 15:35:18 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/176b8275d35d
\ No newline at end of file