Commit 56ded8d6 by Karl Udu

Enkooder saadab MQTT sõnumeid

parent a3a6dc7a
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
platform = espressif8266 platform = espressif8266
board = d1_mini board = d1_mini
framework = arduino framework = arduino
;upload_port = COM4 ; vasak ;upload_port = COM4 ; vasak
upload_port = COM5 ; parem upload_port = COM5 ; parem
lib_deps = ITTIoT, ClickEncoder lib_deps = ITTIoT, ClickEncoder
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
ClickEncoder encoder = ClickEncoder(ENC_PINA, ENC_PINB, ENC_BTN, ENC_STEPS_PER_NOTCH); ClickEncoder encoder = ClickEncoder(ENC_PINA, ENC_PINB, ENC_BTN, ENC_STEPS_PER_NOTCH);
#define LEVEL_MIN 0 #define LEVEL_MIN 0
#define LEVEL_MAX 99 #define LEVEL_MAX 255
#define LEVEL_DEFAULT 50 #define LEVEL_DEFAULT 127
uint32_t level = LEVEL_DEFAULT; #define LEVEL_STEP 4
int32_t level = LEVEL_DEFAULT;
void iot_connected() void iot_connected()
{ {
...@@ -28,43 +29,44 @@ void setup() ...@@ -28,43 +29,44 @@ void setup()
Serial.begin(115200); // setting up serial connection parameter Serial.begin(115200); // setting up serial connection parameter
Serial.println("Booting"); Serial.println("Booting");
/*iot.setConfig("wname", WIFI_NAME); iot.setConfig("wname", WIFI_NAME);
iot.setConfig("wpass", WIFI_PASSWORD); iot.setConfig("wpass", WIFI_PASSWORD);
iot.setConfig("msrv", "193.40.245.72"); iot.setConfig("msrv", "193.40.245.72");
iot.setConfig("mport", "1883"); iot.setConfig("mport", "1883");
iot.setConfig("muser", "test"); iot.setConfig("muser", "test");
iot.setConfig("mpass", "test"); iot.setConfig("mpass", "test");
iot.printConfig(); // print IoT json config to serial iot.printConfig(); // print IoT json config to serial
iot.setup(); // Initialize IoT library*/ iot.setup(); // Initialize IoT library
} }
void loop() 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); delay(5);
encoder.service(); encoder.service();
static int16_t oldPosition, newPosition; static int16_t oldPosition, newPosition;
newPosition += encoder.getValue(); // Read encoder value newPosition += encoder.getValue(); // Read encoder value
char StrBuf[16];
if(newPosition > oldPosition) if(newPosition > oldPosition)
{ {
if(level != LEVEL_MAX) if(level != LEVEL_MAX)
{ {
level++; level += LEVEL_STEP;
//iot.publishMsg("enc", level); if(level > LEVEL_MAX) level = LEVEL_MAX;
Serial.print("level "); sprintf(StrBuf, "%d", level);
Serial.println(level); iot.publishMsg("light_level", StrBuf);
} }
} }
else if (newPosition < oldPosition) else if (newPosition < oldPosition)
{ {
if(level != LEVEL_MIN) if(level != LEVEL_MIN)
{ {
level--; level -= LEVEL_STEP;
//iot.publishMsg("enc", level); if(level < LEVEL_MIN) level = LEVEL_MIN;
Serial.print("level "); sprintf(StrBuf, "%d", level);
Serial.println(level); iot.publishMsg("light_level", StrBuf);
} }
} }
oldPosition = newPosition; 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