File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -72,3 +72,17 @@ uint16_t sfeDevSoilMoisture::readMoistureValue(void)
7272
7373 return value;
7474}
75+
76+ // ----------------------------------------------------------------------------------------
77+ sfeTkError_t sfeDevSoilMoisture::changeSensorAddress (uint8_t newAddress)
78+ {
79+ if (_theBus == nullptr )
80+ return kSTkErrFail ;
81+
82+ // Validate the new address
83+ if (newAddress < 0x07 || newAddress > 0x78 )
84+ return kSTkErrFail ;
85+
86+ // Send the command to change the address
87+ return _theBus->writeRegisterByte (kCommandChangeAddress , newAddress);
88+ }
Original file line number Diff line number Diff line change @@ -43,6 +43,11 @@ class sfeDevSoilMoisture
4343 // / @return The moisture value - a resistance reading between 0 and 1023
4444 uint16_t readMoistureValue (void );
4545
46+ // / @brief Changes the I2C address of the sensor
47+ // / @param newAddress The new I2C address to assign to the sensor
48+ // / @return kSTkErrOk if successful, otherwise an error code
49+ sfeTkError_t changeSensorAddress (uint8_t newAddress);
50+
4651 protected:
4752 // The I2C bus the sensor is connected to
4853 sfeTkII2C *_theBus;
You can’t perform that action at this time.
0 commit comments