Diskrete Nummer unterstützt, Kalibrierungen

This commit is contained in:
starcalc 2018-07-03 21:28:15 +02:00
parent 9260cefb6e
commit c9e6762030
1 changed files with 23 additions and 4 deletions

View File

@ -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() { void setup() {
Serial.begin(115200); Serial.begin(115200);
dialer.setup(); dialer.setup();
Homie_setFirmware(FW_NAME, FW_VERSION); Homie_setFirmware(FW_NAME, FW_VERSION);
Homie_setBrand(FW_NAME); Homie_setBrand(FW_NAME);
dialNode.advertise("number"); dialNode.advertise("dialed");
dialNode.advertise("meter").settable(meterHandler); dialNode.advertise("meter").settable(meterHandler);
dialNode.advertise("number").settable(numberHandler);
Homie.setLoopFunction(loopHandler); Homie.setLoopFunction(loopHandler);
Homie.setup(); Homie.setup();
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
@ -47,11 +61,16 @@ void loop() {
if (dialer.update()) { if (dialer.update()) {
int ivalue = dialer.getNextNumber(); int ivalue = dialer.getNextNumber();
// Serial.println(dialer.getNextNumber()); // Serial.println(dialer.getNextNumber());
dialNode.setProperty("number").send(String(ivalue)); dialNode.setProperty("dialed").send(String(ivalue));
setMeter(ivalue*10); setNumber(ivalue);
} }
} }
void setMeter(int pos){ 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));
}