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.
Dependents: ISR_Mini-explorer_Rangefinder
Fork of ISR_Mini-explorer by
Rangefinder.cpp
00001 #include "Rangefinder.h" 00002 #include "mbed.h" 00003 00004 const int rgfAddr = 0x14; 00005 uint16_t rgfMeasurements[16]; 00006 char sensors_selection[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}; // Only allows a maximum of 11 sensors simultaneously. 00007 00008 I2C* _i2c; 00009 Mutex* _mutex; 00010 00011 void init_rangefinder(I2C* i2c_in, Mutex* mutex_in) 00012 { 00013 _i2c = i2c_in; 00014 _mutex = mutex_in; 00015 wait(1); 00016 _mutex->lock(); 00017 _i2c->write(rgfAddr, sensors_selection, 16); 00018 _mutex->unlock(); 00019 wait(1); 00020 } 00021 00022 int read_rangefinder() 00023 { 00024 int i2c_result; 00025 00026 _mutex->lock(); 00027 i2c_result = _i2c->read(rgfAddr, (char*)rgfMeasurements, sizeof(rgfMeasurements)); 00028 _mutex->unlock(); 00029 00030 return i2c_result; 00031 }
Generated on Fri Jul 15 2022 01:53:00 by
1.7.2
