Rotary-Dial/examples/dialtoserial/dialtoserial.ino

58 lines
1.3 KiB
C++

#include <Homie.h>
#include <ArduinoOTA.h>
#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;
}
}
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);
ArduinoOTA.begin();
}
void loopHandler()
{
}
void loop() {
Homie.loop();
ArduinoOTA.handle();
if (dialer.update()) {
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));
}