-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTDButton.ino
59 lines (47 loc) · 1.48 KB
/
MTDButton.ino
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
// CRITICAL!!!!!!!!!!
// Boards -> Boards Manager -> esp8266 -> install version 2.7.4.
// Newer WILL fail to compile.
// IDE Settings:
// Tools->Board : "WeMos D1 R2 & mini"
// Tools->Flash Size : "4M (1M SPIFFS)"
// Tools->CPU Frequency : "160 MHz"
// Tools->Upload Speed : "921600"
#include <Streaming.h>
#include <Metro.h>
#include <Bounce2.h>
#include <ESPHelper.h>
#include <ESPHelperFS.h>
#include <MTD_Hotlantis.h>
// wire it up
const boolean onReading = false;
// devices with the light shield block access to D5-D8
#define PIN_BUTTON D3 // wire D3/GPIO0 through a N.O. switch to GND
Bounce button = Bounce();
String buttonTopic;
void setup() {
// for local output
Serial.begin(115200);
Serial << endl << endl << endl << "Startup: begin." << endl;
// enable pin.
button.attach(PIN_BUTTON, INPUT_PULLUP);
button.interval(5); // interval in ms
// bootstrap new microcontrollers, if needed.
Comms.saveStuff("publishTopic", Comms.senseMTDButton[2]);
buttonTopic = Comms.loadStuff("publishTopic");
Serial << "Startup: publishing to topic [" << buttonTopic << "]." << endl;
// configure comms
Comms.begin(buttonTopic, processMessages);
Serial << "Startup: complete." << endl;
}
void loop() {
// comms handling
Comms.loop();
// update buttons
if ( button.update() ) {
// publish new reading.
Comms.pub(buttonTopic, Comms.messageBinary[button.read() == onReading]);
}
}
// processes messages that arrive
void processMessages(String topic, String message) {
}