diff options
author | Wolfgang (Wolle) Ewald <wolfgang.ewald@wolles-elektronikkiste.de> | 2021-05-14 17:37:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-14 17:37:31 +0200 |
commit | 67fad4efcb3adc53a697d3d138b2981b1d1b1400 (patch) | |
tree | cfd30620201490cfb2fe27d457399106f9e9218c /src/ADS1115_WE.cpp | |
parent | Update Auto_Range.ino (diff) | |
download | ADS1115_WE-67fad4efcb3adc53a697d3d138b2981b1d1b1400.tar ADS1115_WE-67fad4efcb3adc53a697d3d138b2981b1d1b1400.tar.gz ADS1115_WE-67fad4efcb3adc53a697d3d138b2981b1d1b1400.tar.bz2 ADS1115_WE-67fad4efcb3adc53a697d3d138b2981b1d1b1400.tar.lz ADS1115_WE-67fad4efcb3adc53a697d3d138b2981b1d1b1400.tar.xz ADS1115_WE-67fad4efcb3adc53a697d3d138b2981b1d1b1400.tar.zst ADS1115_WE-67fad4efcb3adc53a697d3d138b2981b1d1b1400.zip |
Diffstat (limited to 'src/ADS1115_WE.cpp')
-rw-r--r-- | src/ADS1115_WE.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/ADS1115_WE.cpp b/src/ADS1115_WE.cpp index 47ed03d..dad4c41 100644 --- a/src/ADS1115_WE.cpp +++ b/src/ADS1115_WE.cpp @@ -17,22 +17,35 @@ #include "ADS1115_WE.h"
ADS1115_WE::ADS1115_WE(int addr){
+ _wire = &Wire;
i2cAddress = addr;
}
ADS1115_WE::ADS1115_WE(){
+ _wire = &Wire;
i2cAddress = 0x48;
}
+ADS1115_WE::ADS1115_WE(TwoWire *w, int addr){
+ _wire = w;
+ i2cAddress = addr;
+}
+
+ADS1115_WE::ADS1115_WE(TwoWire *w){
+ _wire = w;
+ i2cAddress = 0x48;
+}
+
+
void ADS1115_WE::reset(){
- Wire.beginTransmission(0);
- Wire.write(0x06);
- Wire.endTransmission();
+ _wire->beginTransmission(0);
+ _wire->write(0x06);
+ _wire->endTransmission();
}
bool ADS1115_WE::init(){
- Wire.beginTransmission(i2cAddress);
- uint8_t success = Wire.endTransmission();
+ _wire->beginTransmission(i2cAddress);
+ uint8_t success = _wire->endTransmission();
if(success){
return 0;
}
@@ -312,25 +325,25 @@ int16_t ADS1115_WE::calcLimit(float rawLimit){ }
uint8_t ADS1115_WE::writeRegister(uint8_t reg, uint16_t val){
- Wire.beginTransmission(i2cAddress);
+ _wire->beginTransmission(i2cAddress);
uint8_t lVal = val & 255;
uint8_t hVal = val >> 8;
- Wire.write(reg);
- Wire.write(hVal);
- Wire.write(lVal);
- return Wire.endTransmission();
+ _wire->write(reg);
+ _wire->write(hVal);
+ _wire->write(lVal);
+ return _wire->endTransmission();
}
uint16_t ADS1115_WE::readRegister(uint8_t reg){
uint8_t MSByte = 0, LSByte = 0;
uint16_t regValue = 0;
- Wire.beginTransmission(i2cAddress);
- Wire.write(reg);
- Wire.endTransmission();
- Wire.requestFrom(i2cAddress,2);
- if(Wire.available()){
- MSByte = Wire.read();
- LSByte = Wire.read();
+ _wire->beginTransmission(i2cAddress);
+ _wire->write(reg);
+ _wire->endTransmission();
+ _wire->requestFrom(i2cAddress,2);
+ if(_wire->available()){
+ MSByte = _wire->read();
+ LSByte = _wire->read();
}
regValue = (MSByte<<8) + LSByte;
return regValue;
|