2018-04-26 21:45:30 +00:00
|
|
|
#include <Homie.h>
|
|
|
|
#include <ArduinoOTA.h>
|
2018-04-26 16:10:33 +00:00
|
|
|
|
2018-04-26 21:10:18 +00:00
|
|
|
#include "RotaryDialer.h"
|
2018-04-26 16:10:33 +00:00
|
|
|
|
2018-04-26 21:10:18 +00:00
|
|
|
#define PIN_READY D6
|
|
|
|
#define PIN_PULSE D5
|
2018-04-26 21:45:30 +00:00
|
|
|
#define FW_NAME "esp-waehlscheibe"
|
|
|
|
#define FW_VERSION "1.0.0"
|
2018-04-26 16:10:33 +00:00
|
|
|
|
2018-04-30 23:06:59 +00:00
|
|
|
HomieNode dialNode("dial", "dialnode");
|
2018-04-26 16:10:33 +00:00
|
|
|
RotaryDialer dialer = RotaryDialer(PIN_READY, PIN_PULSE);
|
|
|
|
|
2018-04-30 23:06:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 16:10:33 +00:00
|
|
|
void setup() {
|
2018-04-26 21:10:18 +00:00
|
|
|
Serial.begin(115200);
|
2018-04-26 16:10:33 +00:00
|
|
|
dialer.setup();
|
2018-04-26 21:45:30 +00:00
|
|
|
Homie_setFirmware(FW_NAME, FW_VERSION);
|
|
|
|
Homie_setBrand(FW_NAME);
|
|
|
|
dialNode.advertise("number");
|
2018-04-30 23:06:59 +00:00
|
|
|
dialNode.advertise("meter").settable(meterHandler);
|
2018-04-26 21:45:30 +00:00
|
|
|
Homie.setLoopFunction(loopHandler);
|
|
|
|
Homie.setup();
|
|
|
|
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
|
|
|
|
ArduinoOTA.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loopHandler()
|
|
|
|
{
|
2018-04-26 16:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2018-04-26 21:45:30 +00:00
|
|
|
Homie.loop();
|
|
|
|
ArduinoOTA.handle();
|
2018-04-26 16:10:33 +00:00
|
|
|
if (dialer.update()) {
|
2018-04-26 21:45:30 +00:00
|
|
|
int ivalue = dialer.getNextNumber();
|
|
|
|
// Serial.println(dialer.getNextNumber());
|
|
|
|
dialNode.setProperty("number").send(String(ivalue));
|
2018-04-30 23:06:59 +00:00
|
|
|
setMeter(ivalue*10);
|
2018-04-26 16:10:33 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-30 23:06:59 +00:00
|
|
|
|
|
|
|
void setMeter(int pos){
|
|
|
|
analogWrite(D1,map(pos,0,100,0,796));
|
|
|
|
}
|