Commit 56ded8d6 by Karl Udu

Enkooder saadab MQTT sõnumeid

parent a3a6dc7a
......@@ -12,6 +12,7 @@
platform = espressif8266
board = d1_mini
framework = arduino
;upload_port = COM4 ; vasak
upload_port = COM5 ; parem
lib_deps = ITTIoT, ClickEncoder
......
......@@ -13,9 +13,10 @@
ClickEncoder encoder = ClickEncoder(ENC_PINA, ENC_PINB, ENC_BTN, ENC_STEPS_PER_NOTCH);
#define LEVEL_MIN 0
#define LEVEL_MAX 99
#define LEVEL_DEFAULT 50
uint32_t level = LEVEL_DEFAULT;
#define LEVEL_MAX 255
#define LEVEL_DEFAULT 127
#define LEVEL_STEP 4
int32_t level = LEVEL_DEFAULT;
void iot_connected()
{
......@@ -28,43 +29,44 @@ void setup()
Serial.begin(115200); // setting up serial connection parameter
Serial.println("Booting");
/*iot.setConfig("wname", WIFI_NAME);
iot.setConfig("wname", WIFI_NAME);
iot.setConfig("wpass", WIFI_PASSWORD);
iot.setConfig("msrv", "193.40.245.72");
iot.setConfig("mport", "1883");
iot.setConfig("muser", "test");
iot.setConfig("mpass", "test");
iot.printConfig(); // print IoT json config to serial
iot.setup(); // Initialize IoT library*/
iot.setup(); // Initialize IoT library
}
void loop()
{
//iot.handle(); // IoT behind the plan work, it should be periodically called
iot.handle(); // IoT behind the plan work, it should be periodically called
delay(5);
encoder.service();
static int16_t oldPosition, newPosition;
newPosition += encoder.getValue(); // Read encoder value
char StrBuf[16];
if(newPosition > oldPosition)
{
if(level != LEVEL_MAX)
{
level++;
//iot.publishMsg("enc", level);
Serial.print("level ");
Serial.println(level);
level += LEVEL_STEP;
if(level > LEVEL_MAX) level = LEVEL_MAX;
sprintf(StrBuf, "%d", level);
iot.publishMsg("light_level", StrBuf);
}
}
else if (newPosition < oldPosition)
{
if(level != LEVEL_MIN)
{
level--;
//iot.publishMsg("enc", level);
Serial.print("level ");
Serial.println(level);
level -= LEVEL_STEP;
if(level < LEVEL_MIN) level = LEVEL_MIN;
sprintf(StrBuf, "%d", level);
iot.publishMsg("light_level", StrBuf);
}
}
oldPosition = newPosition;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment