Skip to content

Commit 9d919c6

Browse files
committed
tested with field
1 parent c32b677 commit 9d919c6

File tree

2 files changed

+154
-30
lines changed

2 files changed

+154
-30
lines changed

ScoreWindow/ScoreWindow.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void draw() {
298298
(byte)(((int(totalMatchTime-matchTime))&16256)>>7),
299299
(byte)(((int(totalMatchTime-matchTime))&127)),
300300
(byte)((blueSwitch()?1:0)|((byte)(redSwitch()?1:0)<<1)|((byte)(blueScale()?1:0)<<2)|((byte)(redScale()?1:0)<<3)),
301-
(byte)(constrain(int(redScore)-int(blueScore), -1, 1)),
301+
(byte)(constrain(int(redScore)-int(blueScore), -1, 1)+10),
302302
(byte)(constrain(redScore/5, 0, 200)),
303303
(byte)(constrain(blueScore/5, 0, 200)),
304304
(byte)(255)};

lightsArduino/lightsArduino.ino

Lines changed: 153 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
#include <FastLED.h>
22

3-
#define lctR 300
4-
#define lctB 399
5-
#define R_PIN 6
6-
#define B_PIN 7
3+
#define lctR 240
4+
#define lctB 225
5+
#define R_PIN 1
6+
#define B_PIN 0
77
CRGB ledsR[lctR];
88
CRGB ledsB[lctB];
99

10+
#define redNearS 0
11+
#define redNearE 69
12+
#define redSideS 73
13+
#define redSideE 145
14+
#define redAwayS 151
15+
#define redAwayE 220
16+
#define loopRedS 225
17+
#define loopRedE 240
18+
#define bluNearS 0
19+
#define bluNearE 69
20+
#define bluSideS 73
21+
#define bluSideE 145
22+
#define bluAwayS 151
23+
#define bluAwayE 220
24+
25+
CRGB matchTimeBackground = CRGB(40, 40, 0);
26+
CRGB matchTimeForeground = CRGB(0, 220, 0);
27+
CRGB climbColor = CRGB(255, 255, 0);
28+
29+
int matchLength = 300;
30+
int climbTime = 30;
31+
1032
int serialI = 0;
1133

12-
int matchState = 0;
34+
int matchState = -2;
1335
int matchTime = 0;
1436
bool blueSwitch = false;
1537
bool redSwitch = false;
@@ -23,8 +45,10 @@ void setup()
2345
{
2446
Serial.begin(250000);
2547
delay(2000);
26-
FastLED.addLeds<WS2812B, R_PIN, GRB>(ledsR, lctR);
27-
FastLED.addLeds<WS2812B, B_PIN, GRB>(ledsB, lctB);
48+
FastLED.addLeds<WS2812, R_PIN, GRB>(ledsR, lctR);
49+
FastLED.addLeds<WS2812, B_PIN, GRB>(ledsB, lctB);
50+
FastLED.setBrightness(100);
51+
2852
}
2953
void loop()
3054
{
@@ -44,7 +68,7 @@ void loop()
4468
redSwitch = bitRead(buffer[4], 1);
4569
blueScale = bitRead(buffer[4], 2);
4670
redScale = bitRead(buffer[4], 3);
47-
winner = constrain((char)((int)buffer[5] - 10), -1, 1); // 1=red, 0=tie, -1=blue
71+
winner = constrain((((int)buffer[5]) - 10), -1, 1); // 1=red, 0=tie, -1=blue
4872
redScore = constrain(5 * buffer[6], 0, 1000);
4973
blueScore = constrain(5 * buffer[7], 0, 1000);
5074

@@ -68,27 +92,127 @@ void loop()
6892
}
6993
}
7094
// display lights
71-
ledsR[0] = CRGB(255, 0, 0);
72-
ledsR[1] = CRGB(0, 255, 0);
73-
ledsR[2] = CRGB(0, 255, 0);
74-
ledsR[3] = CRGB(0, 0, 255);
75-
ledsR[4] = CRGB(0, 0, 255);
76-
ledsR[5] = CRGB(0, 0, 255);
77-
ledsR[6] = CRGB(0, 0, 0);
78-
ledsR[lctR - 3] = CRGB(250, 0, 0);
79-
ledsR[lctR - 2] = CRGB(250, 0, 0);
80-
ledsR[lctR - 1] = CRGB(250, 0, 0);
81-
82-
ledsB[0] = CRGB(255, 0, 0);
83-
ledsB[1] = CRGB(0, 255, 0);
84-
ledsB[2] = CRGB(0, 255, 0);
85-
ledsB[3] = CRGB(0, 0, 255);
86-
ledsB[4] = CRGB(0, 0, 255);
87-
ledsB[5] = CRGB(0, 0, 255);
88-
ledsB[6] = CRGB(0, 0, 0);
89-
ledsB[lctB - 3] = CRGB(0, 0, 250);
90-
ledsB[lctB - 2] = CRGB(0, 0, 250);
91-
ledsB[lctB - 1] = CRGB(0, 0, 250);
95+
switch (matchState) {
96+
case -1:
97+
for (int i = bluNearS; i <= bluAwayE; i ++) {
98+
ledsB[i] = CHSV(millis() / 4 - i * 10 * 255 / (bluAwayE - bluNearS + redAwayE - redNearS), 150, 70);
99+
}
100+
for (int i = redAwayE; i >= redNearS ; i --) {
101+
ledsR[i] = CHSV(millis() / 4 - i * 10 * 255 / (bluAwayE - bluNearS + redAwayE - redNearS), 150, 70);
102+
}
103+
for (int i = loopRedS; i <= loopRedE; i++) {
104+
ledsR[i] = CHSV(millis() / 10 + i * 20, 200, ((millis() / 30) % (loopRedE - loopRedS + 1) == i - loopRedS) ? 255 : 120);
105+
}
106+
for (int i = redNearS + 5; i <= redAwayE; i += 10) {
107+
ledsR[i - 1] = CRGB(255, 0, 0);
108+
ledsR[i] = CRGB(255, 0, 0);
109+
ledsR[i + 1] = CRGB(255, 0, 0);
110+
}
111+
for (int i = bluNearS + 5; i <= bluAwayE; i += 10) {
112+
ledsB[i - 1] = CRGB(0, 0, 255);
113+
ledsB[i] = CRGB(0, 0, 255);
114+
ledsB[i + 1] = CRGB(0, 0, 255);
115+
}
116+
break;
117+
case 0:
118+
FastLED.clear();
119+
for (int i = redSideS; i <= redSideE; i++) {
120+
ledsR[i] = CRGB(sin8(millis() / 16) / 8 + 100, 0, 0);
121+
}
122+
for (int i = bluSideS; i <= bluSideE; i++) {
123+
ledsB[i] = CRGB(0, 0, sin8(millis() / 16) / 8 + 100);
124+
}
125+
126+
for (int i = redNearS; i <= redNearE; i ++) {
127+
if (-i + redNearE > matchTime * (redNearE - redNearS) / matchLength) {
128+
ledsR[i] = matchTimeBackground;
129+
} else {
130+
ledsR[i] = matchTimeForeground;
131+
}
132+
if (matchLength - matchTime <= climbTime) {
133+
if ((i + (millis() / 100)) % 12 == 0) {
134+
ledsR[i] = climbColor;
135+
}
136+
}
137+
}
138+
for (int i = bluNearS; i <= bluNearE; i ++) {
139+
if (-i + bluNearE > matchTime * (bluNearE - bluNearS) / matchLength) {
140+
ledsB[i] = matchTimeBackground;
141+
} else {
142+
ledsB[i] = matchTimeForeground;
143+
}
144+
if (matchLength - matchTime <= climbTime) {
145+
if ((i + (millis() / 100)) % 12 == 0) {
146+
ledsB[i] = climbColor;
147+
}
148+
}
149+
}
150+
for (int i = redAwayS; i <= redAwayE; i ++) {
151+
if (i - redAwayS > matchTime * (redAwayE - redAwayS) / matchLength) {
152+
ledsR[i] = matchTimeBackground;
153+
} else {
154+
ledsR[i] = matchTimeForeground;
155+
}
156+
if (matchLength - matchTime <= climbTime) {
157+
if ((-i + (millis() / 100)) % 12 == 0) {
158+
ledsR[i] = climbColor;
159+
}
160+
}
161+
}
162+
for (int i = bluAwayS; i <= bluAwayE; i ++) {
163+
if (i - bluAwayS > matchTime * (bluAwayE - bluAwayS) / matchLength) {
164+
ledsB[i] = matchTimeBackground;
165+
} else {
166+
ledsB[i] = matchTimeForeground;
167+
}
168+
169+
if (matchLength - matchTime <= climbTime) {
170+
if ((-i + (millis() / 100)) % 12 == 0) {
171+
ledsB[i] = climbColor;
172+
}
173+
}
174+
}
175+
176+
break;
177+
case 1:
178+
for (int i = bluNearS; i <= bluAwayE; i ++) {
179+
ledsB[i] = CRGB(100, 0, 100);
180+
}
181+
for (int i = redAwayE; i >= redNearS ; i --) {
182+
ledsR[i] = CRGB(100, 0, 100);
183+
}
184+
for (int i = loopRedS; i <= loopRedE; i++) {
185+
ledsR[i] = CHSV(millis() / 10 + i * 20, 200, ((millis() / 30) % (loopRedE - loopRedS + 1) == i - loopRedS) ? 255 : 120);
186+
}
187+
188+
break;
189+
case 2:
190+
191+
for (int i = bluNearS; i <= bluAwayE; i ++) {
192+
if (winner == 1) {
193+
ledsB[i] = CRGB(220, 0, 0);
194+
} else if (winner == -1) {
195+
ledsB[i] = CRGB(0, 0, 220);
196+
} else {
197+
ledsB[i] = CRGB(200, 200, 0);
198+
}
199+
}
200+
for (int i = redAwayE; i >= redNearS ; i --) {
201+
if (winner == 1) {
202+
ledsR[i] = CRGB(220, 0, 0);
203+
} else if (winner == -1) {
204+
ledsR[i] = CRGB(0, 0, 220);
205+
} else {
206+
ledsR[i] = CRGB(200, 200, 0);
207+
}
208+
}
209+
break;
210+
default:
211+
FastLED.clear();
212+
break;
213+
}
214+
92215
FastLED.show();
93216
delay(1);
217+
94218
}

0 commit comments

Comments
 (0)