Hi,
How do I convert Arduino code to Openhab code to find maximum sensor value?
Arduino code:
const int sensorPin = A0;
int sensorReading = 0;
int maxReading = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
sensorReading = analogRead(sensorPin);
if (sensorReading > maxReading) maxReading = sensorReading;
Serial.print(maxReading);
Serial.print('\t');
Serial.println(sensorReading);
delay(100);
}
Openhab rule code:
rule "FSR Maximum"
when
Item itm_hj_fsranalog_mqtt received update
then
var int maxfsr = 0
var int fsranalog123 = (itm_hj_fsranalog_mqtt.state as DecimalType).intValue
if (fsranalog123 > maxfsr){
maxfsr = fsranalog123;
postUpdate(Maxfsr, maxfsr)
}
end
I tried to convert the code. In Arduino, the sensors gave the maximum value.
But, in Openhab it followed the sensor real time value.
Can you help me, how to solve this?