Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 I2C i2c(D4, D5); 00004 Serial pc(USBTX, USBRX); 00005 00006 int getDis() 00007 { 00008 char data[2]; 00009 00010 data[0] = 0x00; 00011 data[1] = 0x51; 00012 int ack = i2c.write(0xE0,data,2); 00013 wait_ms(30); 00014 00015 char reg = 0x02; 00016 ack = i2c.write(0xE0,®,1); 00017 ack = i2c.read(0xE1,data,2); 00018 return (data[0] << 8) | data[1]; 00019 } 00020 00021 int main() { 00022 pc.baud(115200); 00023 pc.printf("st\r\n"); 00024 i2c.frequency(400000); 00025 00026 while(1) { 00027 00028 int dist = getDis(); 00029 pc.printf("%d\r\n",dist); 00030 //wait_ms(50); 00031 00032 } 00033 }
Generated on Sat Aug 6 2022 17:56:10 by
1.7.2