Energy harvesting mobile robot. Developed at Institute of Systems and Robotics — University of Coimbra.

Dependencies:   RF24

Dependents:   ISR_Mini-explorer_Rangefinder

Fork of ISR_Mini-explorer by ISR UC

Committer:
fabiofaria
Date:
Thu Apr 19 15:44:26 2018 +0000
Revision:
4:f6fddeae358e
Child:
5:43215ff15665
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fabiofaria 4:f6fddeae358e 1 #include "Rangefinder.h"
fabiofaria 4:f6fddeae358e 2 #include "mbed.h"
fabiofaria 4:f6fddeae358e 3
fabiofaria 4:f6fddeae358e 4 const int rgfAddr = 0x14;
fabiofaria 4:f6fddeae358e 5 uint16_t rgfMeasurements[16];
fabiofaria 4:f6fddeae358e 6 //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.
fabiofaria 4:f6fddeae358e 7 //char sensors_selection[] = {1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0}; // Only allows a maximum of 11 sensors simultaneously.
fabiofaria 4:f6fddeae358e 8 char sensors_selection[] = {1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0}; // Only allows a maximum of 11 sensors simultaneously.
fabiofaria 4:f6fddeae358e 9
fabiofaria 4:f6fddeae358e 10 I2C* _i2c;
fabiofaria 4:f6fddeae358e 11 Mutex* _mutex;
fabiofaria 4:f6fddeae358e 12
fabiofaria 4:f6fddeae358e 13 void init_rangefinder(I2C* i2c_in, Mutex* mutex_in)
fabiofaria 4:f6fddeae358e 14 {
fabiofaria 4:f6fddeae358e 15 _i2c = i2c_in;
fabiofaria 4:f6fddeae358e 16 _mutex = mutex_in;
fabiofaria 4:f6fddeae358e 17 wait(1);
fabiofaria 4:f6fddeae358e 18 _mutex->lock();
fabiofaria 4:f6fddeae358e 19 _i2c->write(rgfAddr, sensors_selection, 16);
fabiofaria 4:f6fddeae358e 20 _mutex->unlock();
fabiofaria 4:f6fddeae358e 21 wait(1);
fabiofaria 4:f6fddeae358e 22 }
fabiofaria 4:f6fddeae358e 23
fabiofaria 4:f6fddeae358e 24 int read_rangefinder()
fabiofaria 4:f6fddeae358e 25 {
fabiofaria 4:f6fddeae358e 26 int i2c_result;
fabiofaria 4:f6fddeae358e 27
fabiofaria 4:f6fddeae358e 28 _mutex->lock();
fabiofaria 4:f6fddeae358e 29 i2c_result = _i2c->read(rgfAddr, (char*)rgfMeasurements, sizeof(rgfMeasurements));
fabiofaria 4:f6fddeae358e 30 _mutex->unlock();
fabiofaria 4:f6fddeae358e 31
fabiofaria 4:f6fddeae358e 32 return i2c_result;
fabiofaria 4:f6fddeae358e 33 }