-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLightTree.cpp
More file actions
171 lines (158 loc) · 3.9 KB
/
Copy pathLightTree.cpp
File metadata and controls
171 lines (158 loc) · 3.9 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*****************************************
* RemoteArDuino (RAD) Gate
* (c) Danny Frencham 2017
*****************************************/
#include <Adafruit_NeoPixel.h>
#include "constants.h"
#include "LightTree.h"
int rgbMode = 0;
bool modeRelay = false;
LightTree::LightTree() { }
void LightTree::initialise(bool useRelays, int pin) {
if (useRelays) {
modeRelay = useRelays;
pinMode(PIN_LIGHT_TREE_RELAY_1, OUTPUT);
pinMode(PIN_LIGHT_TREE_RELAY_2, OUTPUT);
pinMode(PIN_LIGHT_TREE_RELAY_3, OUTPUT);
pinMode(PIN_LIGHT_TREE_RELAY_4, OUTPUT);
led_reset();
}
else
{
#ifdef HARDWARE_NEOPIXEL_RGB
_strip = Adafruit_NeoPixel(8, pin, NEO_GRB + NEO_KHZ800);
// need to use different colours for RGB stick
rgbMode = 1;
#endif
#ifdef HARDWARE_NEOPIXEL_RGBW
_strip = Adafruit_NeoPixel(8, pin, NEO_RGBW + NEO_KHZ800);
#endif
_strip.begin();
// _strip.setBrightness(100); dull
_strip.setBrightness(255); // blinding
}
}
void LightTree::light_set(int step, Gate* gate) {
serial_print_val("Set LED", step);
switch (step) {
case 1:
led_reset();
modeRelay ? light_set_relay(step) : light_set_pixel(step);
break;
case 2:
case 3:
modeRelay ? light_set_relay(step) : light_set_pixel(step);
break;
case 4:
gate->drop();
modeRelay ? light_set_relay(step) : light_set_pixel(step);
break;
default:
led_reset();
}
}
void LightTree::led_reset() {
if (modeRelay) {
digitalWrite(PIN_LIGHT_TREE_RELAY_1, HIGH);
digitalWrite(PIN_LIGHT_TREE_RELAY_2, HIGH);
digitalWrite(PIN_LIGHT_TREE_RELAY_3, HIGH);
digitalWrite(PIN_LIGHT_TREE_RELAY_4, HIGH);
} else {
for(int i=0;i<8;i++) {
_strip.setPixelColor(i,0,0,0,0);
}
_strip.show();
}
}
void LightTree::abort() {
if (modeRelay) {
//digitalWrite(PIN_LIGHT_TREE_RELAY_1, HIGH);
//led_reset();
digitalWrite(PIN_LIGHT_TREE_RELAY_1, HIGH);
digitalWrite(PIN_LIGHT_TREE_RELAY_2, LOW);
digitalWrite(PIN_LIGHT_TREE_RELAY_3, LOW);
digitalWrite(PIN_LIGHT_TREE_RELAY_4, HIGH);
} else {
led_reset();
for(int i=0;i<8;i++) {
_strip.setPixelColor(i,RED);
}
_strip.show();
}
}
void LightTree::ready() {
if (modeRelay) {
led_reset();
} else {
led_reset();
_strip.setPixelColor(0, BLUE);
_strip.show();
}
}
void LightTree::set_status(uint32_t color) {
led_reset();
_strip.setPixelColor(0, color);
_strip.show();
}
void LightTree::light_set_pixel(int step) {
switch (step) {
case 1:
led_reset();
if (rgbMode) {
_strip.setPixelColor(6, RGB_RED);
_strip.setPixelColor(7, RGB_RED);
} else {
_strip.setPixelColor(6, RED);
_strip.setPixelColor(7, RED);
}
break;
case 2:
if (rgbMode) {
_strip.setPixelColor(4, RGB_ORANGE);
_strip.setPixelColor(5, RGB_ORANGE);
} else {
_strip.setPixelColor(4, YELLOW);
_strip.setPixelColor(5, YELLOW);
}
break;
case 3:
if (rgbMode) {
_strip.setPixelColor(2, RGB_ORANGE);
_strip.setPixelColor(3, RGB_ORANGE);
} else {
_strip.setPixelColor(2, YELLOW);
_strip.setPixelColor(3, YELLOW);
}
break;
case 4:
if (rgbMode) {
_strip.setPixelColor(0, RGB_GREEN);
_strip.setPixelColor(1, RGB_GREEN);
} else {
_strip.setPixelColor(0, GREEN);
_strip.setPixelColor(1, GREEN);
}
break;
default:
led_reset();
}
_strip.show();
}
void LightTree::light_set_relay(int step) {
switch (step) {
case 1:
digitalWrite(PIN_LIGHT_TREE_RELAY_1, LOW);
break;
case 2:
digitalWrite(PIN_LIGHT_TREE_RELAY_2, LOW);
break;
case 3:
digitalWrite(PIN_LIGHT_TREE_RELAY_3, LOW);
break;
case 4:
digitalWrite(PIN_LIGHT_TREE_RELAY_4, LOW);
break;
default:
led_reset();
}
}