diff --git a/examples/dialtoserial/dialtoserial.ino b/examples/dialtoserial/dialtoserial.ino index b2795c4..c979564 100644 --- a/examples/dialtoserial/dialtoserial.ino +++ b/examples/dialtoserial/dialtoserial.ino @@ -8,15 +8,29 @@ #define FW_NAME "esp-waehlscheibe" #define FW_VERSION "1.0.0" -HomieNode dialNode("dial", "number"); +HomieNode dialNode("dial", "dialnode"); RotaryDialer dialer = RotaryDialer(PIN_READY, PIN_PULSE); +bool meterHandler(const HomieRange& range, const String& value) { + Homie.getLogger() << "meter " << ": " << value << endl; + int iValue = value.toInt(); + if ((iValue >= 0) && (iValue <=100)) + { + setMeter(value.toInt()); + dialNode.setProperty("meter").send(value); + return true; + } else { + return false; + } +} + void setup() { Serial.begin(115200); dialer.setup(); Homie_setFirmware(FW_NAME, FW_VERSION); Homie_setBrand(FW_NAME); dialNode.advertise("number"); + dialNode.advertise("meter").settable(meterHandler); Homie.setLoopFunction(loopHandler); Homie.setup(); ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); @@ -34,5 +48,10 @@ void loop() { int ivalue = dialer.getNextNumber(); // Serial.println(dialer.getNextNumber()); dialNode.setProperty("number").send(String(ivalue)); + setMeter(ivalue*10); } } + +void setMeter(int pos){ + analogWrite(D1,map(pos,0,100,0,796)); +}