-
Notifications
You must be signed in to change notification settings - Fork 0
/
homeAutomation.ino
61 lines (44 loc) · 1.19 KB
/
homeAutomation.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
60
61
#include <LiquidCrystal.h>
#include <Arduino.h>
#include <AbleButtons.h>
#include "Timer.h"
#include "Screen.h"
#include "structs.h"
#include "Component.h"
#define INC_BTN_PIN A0
#define DEC_BTN_PIN A1
#define START_BTN_PIN 7
#define STATUS_LED_PIN 13
#define DEFAULT_TIME 600 // 10 minutes
using Button = AblePullupClickerButton;
LiquidCrystal LCD(9, 8, 5, 4, 3, 2);
const Screen screen(LCD);
const Component status(LED_BUILTIN);
const Component device(5);
const Button increment(INC_BTN_PIN);
const Button decrement(DEC_BTN_PIN);
const Button start(START_BTN_PIN);
const Timer timer(DEFAULT_TIME);
void setup() {
Serial.begin(9600);
start.begin();
increment.begin();
decrement.begin();
screen.begin();
}
void loop() {
start.handle();
increment.handle();
decrement.handle();
timer.handle();
if (timer.hasChange()) {
screen.print(timer.getValue(), timer.isActive());
}
// resetClicked = click + release event
if (start.resetClicked()) timer.toggle(); // Start/Pause
if (increment.resetClicked()) timer.addOneMinute();
if (decrement.resetClicked()) timer.subOneMinute();
const bool active = timer.isActive();
device.setState(active);
status.setState(active);
}