Framework of classes and program to measure tilt angles using accelerometers
Fork of tilt_angles by
Diff: ENGO333_I2C.cpp
- Revision:
- 0:3bffc1862262
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ENGO333_I2C.cpp Thu Nov 24 23:02:42 2016 +0000 @@ -0,0 +1,39 @@ +#include "ENGO333_I2C.h" + +ENGO333_I2C::ENGO333_I2C(PinName sda, PinName scl) : i2c(sda, scl) +{ + // Do nothing +} + +ENGO333_I2C::~ENGO333_I2C() +{ + // Do nothing +} + +void ENGO333_I2C::setSpeed(int freq) +{ + this->i2c.frequency(freq); +} + +void ENGO333_I2C::writeOneByte(char deviceAddress, char registerAddress, char value) +{ + char temp[2]; + temp[0] = registerAddress; + temp[1] = value; + this->i2c.write(deviceAddress, temp, 2); +} + +char ENGO333_I2C::readOneByte(char deviceAddress, char registerAddress) +{ + char temp = 0; + this->i2c.write(deviceAddress, ®isterAddress, 1); + this->i2c.read(deviceAddress, &temp, 1); + return (char)temp; +} + +void ENGO333_I2C::readBytes(char deviceAddress, char registerAddress, char* value, int length) +{ + this->i2c.write(deviceAddress, ®isterAddress, 1); + this->i2c.read(deviceAddress, value, length); +} +