diff --git a/examples/dialtoserial/dialtoserial.ino b/examples/dialtoserial/dialtoserial.ino index c979564..6e1fd8c 100644 --- a/examples/dialtoserial/dialtoserial.ino +++ b/examples/dialtoserial/dialtoserial.ino @@ -24,13 +24,27 @@ bool meterHandler(const HomieRange& range, const String& value) { } } +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("number"); + dialNode.advertise("dialed"); dialNode.advertise("meter").settable(meterHandler); + dialNode.advertise("number").settable(numberHandler); Homie.setLoopFunction(loopHandler); Homie.setup(); ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); @@ -47,11 +61,16 @@ void loop() { if (dialer.update()) { int ivalue = dialer.getNextNumber(); // Serial.println(dialer.getNextNumber()); - dialNode.setProperty("number").send(String(ivalue)); - setMeter(ivalue*10); + dialNode.setProperty("dialed").send(String(ivalue)); + setNumber(ivalue); } } void setMeter(int pos){ - analogWrite(D1,map(pos,0,100,0,796)); + analogWrite(D1,map(pos,0,100,9,462)); } + +void setNumber(int pos){ + analogWrite(D1,map(pos,0,9,9,462)); +} +