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 /*Program Example 7.8: Configures and takes readings from the SRF08 ultrasonic range finder, and displays them on screen. 00002 */ 00003 #include "mbed.h" 00004 I2C rangefinder(p9, p10); //sda, sc1 00005 Serial pc(USBTX, USBRX); //tx, rx 00006 const int addr = 0xE0; 00007 char config_r[2]; 00008 char range_read[2]; 00009 float range; 00010 00011 int main() { 00012 while (1) { 00013 config_r[0] = 0x00; //set pointer reg to ‘cmd register' 00014 config_r[1] = 0x51; //initialise, result in cm 00015 rangefinder.write(addr, config_r, 2); 00016 wait(0.07); 00017 config_r[0] = 0x02; //set pointer reg to 'data register' 00018 rangefinder.write(addr, config_r, 1); //send to pointer 'read range' 00019 rangefinder.read(addr, range_read, 2); //read the two-byte range data 00020 range = ((range_read[0] << 8) + range_read[1]); 00021 pc.printf("Range = %.2f cm\n\r", range); //print range on screen 00022 wait(0.05); 00023 } 00024 } 00025
Generated on Sun Jul 24 2022 17:27:18 by
1.7.2