-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlocker-sketch.ino
More file actions
59 lines (49 loc) · 1.53 KB
/
Copy pathlocker-sketch.ino
File metadata and controls
59 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <AppKit.h>
#include <Board-WittyCloud.h>
#include <Date.h>
#include <LispPrimitives.h>
#include <Logger.h>
#include <Uniot.h>
using namespace uniot;
#define RELAY_PIN D3
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET);
auto taskPrintHeap = TaskScheduler::make([](short t) {
Serial.println(ESP.getFreeHeap());
});
auto taskCheckRelay = TaskScheduler::make([](short t) {
if (digitalRead(RELAY_PIN)) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(9, 16);
display.println("OPEN");
display.display();
} else {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(3, 16);
display.println("CLOSE");
display.display();
}
});
void inject() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
auto &MainAppKit = AppKit::getInstance(PIN_BUTTON, BTN_PIN_LEVEL, D4);
UniotPinMap.setDigitalOutput(2, RELAY_PIN, D4);
digitalWrite(RELAY_PIN, LOW);
MainEventBus.registerKit(&MainAppKit);
MainScheduler.push(&MainAppKit)
->push(taskCheckRelay)
->push(taskPrintHeap);
taskPrintHeap->attach(500);
taskCheckRelay->attach(50);
MainAppKit.begin();
UNIOT_LOG_INFO("%s: %s", "CHIP_ID", String(ESP.getChipId(), HEX).c_str());
UNIOT_LOG_INFO("%s: %s", "DEVICE_ID", MainAppKit.getCredentials().getDeviceId().c_str());
UNIOT_LOG_INFO("%s: %s", "OWNER_ID", MainAppKit.getCredentials().getOwnerId().c_str());
}