-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixelSevenSegment.cpp
237 lines (132 loc) · 6.51 KB
/
pixelSevenSegment.cpp
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* ~~~~** Neopixel **~~~~** Seven Segment Display Library **~~~~~
pixleSevenSegment.cpp
Library to manage neopixel strips arranged into 7 segment display digits.
The segments are wired in series, and follow the layout of typical 7 segment
displays. Segments: A, B, C, D, E, F, G.
Setups:
Number of LEDS in each Segment
Number of Digits.
Inputs:
individual digit ID & Value
hours, minutes, seconds as char strings or ints
time as complete string
current display colour
specific digit colour
* *
Outputs:
Data to Neopixel string
Serial print of current displayed time/values
*/
#include "pixelSevenSegment.h"
//pixelSevenSegment::pixelSevenSegment(int number_digits , int leds_per_segment, int extra_leds){//
void pixelSevenSegment::sevenSegSetup(byte brightness) {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(ledString, TOTAL_LEDS).setCorrection(TypicalLEDStrip); // This sets up our LED string object
// set master brightness control
FastLED.setBrightness(brightness);
// Sets the brightness for the entire string
currentBrightness = brightness;
}
void pixelSevenSegment::flyingDigit(digitSeg in, savedColour inputColour, uint32_t animationDelay) {
int iteration = 0; // this variable needs to be external
pixelSevenSegment::setDigit_colourName(in, iteration, inputColour);
iteration++;
}
void pixelSevenSegment::setAllDigitsX(digitSeg X, byte r, byte g, byte b) {
pixelSevenSegment::setDigit(X, 0, r, g, b);
pixelSevenSegment::setDigit(X, 1, r, g, b);
pixelSevenSegment::setDigit(X, 2, r, g, b);
pixelSevenSegment::setDigit(X, 3, r, g, b);
pixelSevenSegment::setDigit(X, 4, r, g, b);
pixelSevenSegment::setDigit(X, 5, r, g, b);
}
void pixelSevenSegment::setDigitsBlank() { // Method to set all digits to black (off)
pixelSevenSegment::setDigit(alldigits[8], 0, 0, 0, 0); // Passed Arguments (digitSeg.bitarray, digitNumber, red, green, blue)
pixelSevenSegment::setDigit(alldigits[8], 1, 0, 0, 0); // Passed Arguments (digitSeg.bitarray, digitNumber, red, green, blue)
pixelSevenSegment::setDigit(alldigits[8], 2, 0, 0, 0); // Passed Arguments (digitSeg.bitarray, digitNumber, red, green, blue)
pixelSevenSegment::setDigit(alldigits[8], 3, 0, 0, 0); // Passed Arguments (digitSeg.bitarray, digitNumber, red, green, blue)
pixelSevenSegment::setDigit(alldigits[8], 4, 0, 0, 0); // Passed Arguments (digitSeg.bitarray, digitNumber, red, green, blue)
pixelSevenSegment::setDigit(alldigits[8], 5, 0, 0, 0); // Passed Arguments (digitSeg.bitarray, digitNumber, red, green, blue)
}
// this function needs to be a method for a "digit" object but I couldn't work out how to do that.
// This method is slightly more inelegent but it should work (UNTESTED with more than 1 digit but confident it will function)
void pixelSevenSegment::setDigit_colourName(digitSeg input, int8_t digitNum, savedColour inputColour) {
pixelSevenSegment::setDigit(input, digitNum, inputColour.r, inputColour.g, inputColour.b);
}
void pixelSevenSegment::setDigit (digitSeg current, int8_t digitNumber, uint8_t red, uint8_t green, uint8_t blue ) { // This function sets the first digit based on the data structure passed to it.
// A new instance of digitSeg has been set up ready to take whatever data is placed into it
// After this, a variable to denote which digit we are setting is passed as an argument.
// Also passed to function - rgb colour value, which sets the colour for the entire digit
uint16_t q = ((digitNumber) * (LED_PER_SEG * 7)); // This variable is added onto the array numbers, advancing down the LED array as each successive digit is selected to be written to.
//Serial.println(q);
// Above algorithm may need updating once dots are added, as to sync any animated lighting effects, the led addresses for the : : Dots needs to come between the ids for each digit
int16_t s = 0; // Addr to advance the array through each segement of each digit
if (current.A) {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB(red, green, blue);
} else {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB::Black;
}
s = (LED_PER_SEG);
if (current.B) {
ledString((s + q ), (s + LED_PER_SEG + q - 1)) = CRGB(red, green, blue);
} else {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB::Black;
}
s = ((LED_PER_SEG) * 2);
if (current.C) {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB(red, green, blue);
} else {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB::Black;
}
s = ((LED_PER_SEG) * 3);
if (current.D) {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB(red, green, blue);
} else {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB::Black;
}
s = ((LED_PER_SEG) * 4);
if (current.E) {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB(red, green, blue);
} else {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB::Black;
}
s = ((LED_PER_SEG) * 5);
if (current.F) {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB(red, green, blue);
} else {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB::Black;
}
s = ((LED_PER_SEG) * 6);
if (current.G) {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB(red, green, blue);
} else {
ledString((s + q), (s + LED_PER_SEG + q - 1)) = CRGB::Black;
}
}
// After all the arrays for the digits, ID for the dots starts again at ID:
// (LED_PER_SEG * 7)* 6 to ((LED_PER_SEG * 7)* 6) + 4
void pixelSevenSegment::setDotsRGB(uint8_t red, uint8_t green, uint8_t blue ) {
int16_t d = (LEDS_IN_TPLUS + (LED_PER_SEG * 7) * 6);
ledString(d, (d + 4)) = CRGB(red, green, blue);
}
void pixelSevenSegment::setDotsName(savedColour newColour) {
int16_t d = (LEDS_IN_TPLUS + (LED_PER_SEG * 7) * 6);
ledString(d, (d + 4)) = CRGB(newColour.r, newColour.g, newColour.b);
}
void pixelSevenSegment::setStringRGB(uint16_t start, uint16_t to, uint8_t red, uint8_t green, uint8_t blue) {
ledString(start, to) = CRGB(red, green, blue);
}
void pixelSevenSegment::setStringName(uint16_t start, uint16_t to, savedColour newColour) {
ledString(start, to) = CRGB(newColour.r, newColour.g, newColour.b);
}
void pixelSevenSegment::changeColourRGB(byte red, byte green, byte blue) {
currentColour.r = red;
currentColour.g = green;
currentColour.b = blue;
}
void pixelSevenSegment::changeColourStruc(savedColour newColour) {
currentColour = newColour;
}
void pixelSevenSegment::changeBrightness(byte bright) {
currentBrightness = bright;
FastLED.setBrightness(bright);
}