forked from dfrencham/rad-gate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightTree.cpp
More file actions
135 lines (124 loc) · 3.58 KB
/
Copy pathLightTree.cpp
File metadata and controls
135 lines (124 loc) · 3.58 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
/*****************************************
* RemoteArDuino (RAD) Gate
* (c) Danny Frencham 2017
*****************************************/
#include "constants.h"
#include "LightTree.h"
#include <FastLED.h>
#if LIGHT_TREE_STRIP
CRGB leds[NUM_LEDS];
int team_size = NUM_LEDS/4; // no of LEDS in each color
#endif
LightTree::LightTree() { }
void LightTree::initialise() {
#if (LIGHT_TREE_STRIP)
serial_print("Init Light Strip");
delay(2000); // power-up safety delay
FastLED.addLeds<LED_TYPE, PIN_LED, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.show();
FastLED.setBrightness(BRIGHTNESS);
#endif
#if (LIGHT_TREE_RELAY_ENABLE)
serial_print("Init Light Relays");
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);
#endif
}
void LightTree::led_reset() {
#if (LIGHT_TREE_RELAY_ENABLE)
digitalWrite(PIN_LIGHT_TREE_RELAY_1, !LIGHT_TREE_RELAY_ON);
digitalWrite(PIN_LIGHT_TREE_RELAY_2, !LIGHT_TREE_RELAY_ON);
digitalWrite(PIN_LIGHT_TREE_RELAY_3, !LIGHT_TREE_RELAY_ON);
digitalWrite(PIN_LIGHT_TREE_RELAY_4, !LIGHT_TREE_RELAY_ON);
#endif
#if (LIGHT_TREE_STRIP)
for(int i=0;i<NUM_LEDS;i++) {
leds[i] = CRGB::Black;
}
FastLED.show();
#endif
}
void LightTree::abort() {
#if (LIGHT_TREE_RELAY_ENABLE)
digitalWrite(PIN_LIGHT_TREE_RELAY_1, !LIGHT_TREE_RELAY_ON);
digitalWrite(PIN_LIGHT_TREE_RELAY_2, LIGHT_TREE_RELAY_ON);
digitalWrite(PIN_LIGHT_TREE_RELAY_3, LIGHT_TREE_RELAY_ON);
digitalWrite(PIN_LIGHT_TREE_RELAY_4, !LIGHT_TREE_RELAY_ON);
#endif
#if (LIGHT_TREE_STRIP)
for(int i=0;i<NUM_LEDS;i++) {
leds[i] = CRGB::Red;
}
FastLED.show();
#endif
}
void LightTree::ready() {
led_reset();
#if (LIGHT_TREE_STRIP)
leds[0] = CRGB::Blue;
FastLED.show();
#endif
}
void LightTree::set_status(uint32_t color) {
#if (LIGHT_TREE_STRIP)
leds[0] = color;
FastLED.show();
//FastLED.setBrightness(BRIGHTNESS); // may be needed if builtin LED affecting
#endif
}
void LightTree::light_set(int step) {
serial_print_val("Set LED ", step);
#if (LIGHT_TREE_RELAY_ENABLE)
switch (step) {
case 1:
digitalWrite(PIN_LIGHT_TREE_RELAY_1, LIGHT_TREE_RELAY_ON);
break;
case 2:
digitalWrite(PIN_LIGHT_TREE_RELAY_2, LIGHT_TREE_RELAY_ON);
break;
case 3:
digitalWrite(PIN_LIGHT_TREE_RELAY_3, LIGHT_TREE_RELAY_ON);
break;
case 4:
digitalWrite(PIN_LIGHT_TREE_RELAY_4, LIGHT_TREE_RELAY_ON);
break;
default:
led_reset();
}
#endif
#if (LIGHT_TREE_STRIP)
int position = 4-step; // bottom of strip up
// int position = step-1; // top of strip down
switch (step) {
case 1:
// set team Red LEDs
for(int i=0;i<team_size;i++) {
leds[i+position*team_size] = CRGB::Red;
}
break;
case 2:
// set team Orange LEDs
for(int i=0;i<team_size;i++) {
leds[i+position*team_size] = CRGB::Orange;
}
break;
case 3:
// set 2nd team Orange LEDs
for(int i=0;i<team_size;i++) {
leds[i+position*team_size] = CRGB::Orange;
}
break;
case 4:
//set team Green LEDs
for(int i=0;i<team_size;i++) {
leds[i+position*team_size] = CRGB::Green;
}
break;
default:
led_reset();
}
FastLED.show();
#endif
}