aa

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
akudohune
Date:
Wed Feb 27 02:33:02 2013 +0000
Commit message:
aaa

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
diff -r 000000000000 -r e455520e1583 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 27 02:33:02 2013 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+ 
+I2C i2c(p9, p10);        // sda, scl
+Serial pc(USBTX, USBRX); // tx, rx
+
+#define ADDR 0x14   // define the I2C Address
+
+int main() {
+    char cmd[4];
+    while(1) {
+        cmd[0] = 0x0;            // pointer to command register
+        cmd[1] = 0x51;           // Start ranging, results in cm
+        i2c.write(ADDR, cmd, 2); // Send command string
+ 
+        wait(0.07);              // Could also poll, 65ms is typical
+ 
+        // Set pointer to location 2 (first echo)
+        cmd[0] = 0x2;
+        i2c.write(ADDR, cmd, 1);
+        i2c.read(ADDR, cmd, 2); // read the two-byte echo result
+ 
+        // print the ranging data to the screen
+        float echo = 0.01 * ((cmd[0] << 8) + cmd[1]);
+        pc.printf("Range = %.2f\n", echo);
+        wait(0.1);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r e455520e1583 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Feb 27 02:33:02 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1
\ No newline at end of file