Meter-Funktionalität

This commit is contained in:
starcalc 2018-05-01 01:06:59 +02:00
parent 71dfc33a9c
commit 9260cefb6e
1 changed files with 20 additions and 1 deletions

View File

@ -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));
}