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)
72
72
73
73
return value;
74
74
}
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
43
43
// / @return The moisture value - a resistance reading between 0 and 1023
44
44
uint16_t readMoistureValue (void );
45
45
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
+
46
51
protected:
47
52
// The I2C bus the sensor is connected to
48
53
sfeTkII2C *_theBus;
You can’t perform that action at this time.
0 commit comments