-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindicator_LED.h
60 lines (50 loc) · 1.83 KB
/
indicator_LED.h
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
// ----[Internal LED indicator CONTROL MODULE]-----
#pragma once
#include "sys_logStatus.h"
#include "home_assistant.h"
void onButtonCommand(HAButton* sender)
{
bool state = (digitalRead(LED_BUILTIN) == HIGH);
if (sender == &ha.entities.buttonA) {
// button A was clicked, do your logic here
logText("Button A Pressed");
digitalWrite(LED_BUILTIN, (!state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (!state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (state ? HIGH : LOW));
delay(250);
} else if (sender == &ha.entities.buttonB) {
// button B was clicked, do your logic here
logText("Button B Pressed");
digitalWrite(LED_BUILTIN, (!state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (!state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (!state ? HIGH : LOW));
delay(250);
digitalWrite(LED_BUILTIN, (state ? HIGH : LOW));
delay(250);
}
}
void onSwitchCommand(bool state, HASwitch* sender)
{
//Serial.println("Switch Command");
digitalWrite(LED_BUILTIN, (state ? HIGH : LOW));
sender->setState(state); // report state back to the Home Assistant
}
void setupLedIndicator(void)
{
// light up for startup
pinMode(LED_BUILTIN, OUTPUT);
logStatus("Setting up internal LED controls");
ha.entities.led.onCommand(onSwitchCommand); // attach switch callback
ha.entities.buttonA.onCommand(onButtonCommand); // attach button press callback
ha.entities.buttonB.onCommand(onButtonCommand); // attach button press callback
}