#include #include #include "RotaryDialer.h" #define PIN_READY D6 #define PIN_PULSE D5 #define FW_NAME "esp-waehlscheibe" #define FW_VERSION "1.0.0" 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; } } bool numberHandler(const HomieRange& range, const String& value) { Homie.getLogger() << "number " << ": " << value << endl; int iValue = value.toInt(); if ((iValue >= 0) && (iValue <=100)) { setNumber(value.toInt()); dialNode.setProperty("number").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("dialed"); dialNode.advertise("meter").settable(meterHandler); dialNode.advertise("number").settable(numberHandler); Homie.setLoopFunction(loopHandler); Homie.setup(); ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); ArduinoOTA.begin(); } void loopHandler() { } void loop() { Homie.loop(); ArduinoOTA.handle(); if (dialer.update()) { int ivalue = dialer.getNextNumber(); // Serial.println(dialer.getNextNumber()); dialNode.setProperty("dialed").send(String(ivalue)); setNumber(ivalue); } } void setMeter(int pos){ analogWrite(D1,map(pos,0,100,9,462)); } void setNumber(int pos){ analogWrite(D1,map(pos,0,9,9,462)); }