#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include <FastLED.h>
#define LED_PIN 2
#define NUM_LEDS 560
#define BRIGHTNESS 10
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
// Fail counters
#define FailHomeStartLED 228 // First LED for the Home fail counter
#define FailGuestsStartLED 294 // First LED for the Guests fail counter
#define FailHomeLeftToRight true // Home: true = from left to right, false = from right to left
#define FailGuestsLeftToRight true // Guests: true = from left to right, false = from right to left
#define FailLEDsPerDot 2 // Number of LEDs in a fail dot
#define FailDotCount 5 // Number of fails/dots for Home or Guests
// Fail dot colors
CRGB FailColors[FailDotCount] = { CRGB(255,0,0), CRGB(0,255,0), CRGB(255,0,0), CRGB(0,255,0), CRGB(255,0,0) };
// or use CRGB names;
// CRGB FailColors[FailDotCount] = { CRGB::Yellow, CRGB::Yellow, CRGB::Yellow, CRGB::Orange, CRGB::Red };
// Structure of a number in segments (see end of code for standard - the order here is different)
#define SegmentA 8
#define SegmentB 16
#define SegmentC 48
#define SegmentD 40
#define SegmentE 32
#define SegmentF 0
#define SegmentG 24
// What LED segments are needed for numbers?
// Segments orientation: H V V H V V H
// Segments used: A B C D E F G For number:
byte SegmentNumbers[10][7] = { { 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,1,0,1,1 } }; // 9
// Horizontal/Vertical number of LEDs per segment
#define SegmentHSize 8
#define SegmentVSize 8
// Total number of LEDs per number
#define TotalSegmentSize (3*SegmentHSize)+(4*SegmentVSize)
// Size of time colon - 2 dots, each 2 LEDS
#define TimeSeparatorSize 4
// Assume wiring:
// Start at time minutes -> time colon -> seconds -> Fouls Home -> Period -> Foul Guests -> Score Home -> Score Guests
// Number and colon start positions
#define StartLEDMinutes10 0
#define StartLEDMinutes1 56
#define StartLEDSecondsSeparator 112
#define StartLEDSeconds10 116
#define StartLEDSeconds1 172
#define StartLEDPeriod 238
#define StartLEDScoreHome100 304
#define StartLEDScoreHome10 320
#define StartLEDScoreHome1 376
#define StartLEDScoreGuests100 432
#define StartLEDScoreGuests10 448
#define StartLEDScoreGuests1 504
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS ); // Set overall brightness
FastLED.clear(true); // clear LEDs and Show
}
void loop()
{
SetFail(5,5); // zet de foutelling voor Home (3) en Guests (4)
SetTime(12,43,CRGB::Red);
SetPeriod(StartLEDPeriod, CRGB::Green, 2);
SetScore(12, CRGB::Blue, 2, CRGB::Blue);
}
void SetFail(int FailCountHome, int FailCountGuests) {
int Direction;
FailHomeLeftToRight ? Direction = 1 : Direction = -1;
for(int FailCounter=0; FailCounter<FailCountHome; FailCounter++) {
for(int LEDsInDot=0; LEDsInDot<FailLEDsPerDot; LEDsInDot++) {
leds[FailHomeStartLED + Direction*((FailCounter*FailLEDsPerDot) + LEDsInDot)] = FailColors[FailCounter];
}
}
FailGuestsLeftToRight ? Direction = 1 : Direction = -1;
for(int FailCounter=0; FailCounter<FailCountGuests; FailCounter++) {
for(int LEDsInDot=0; LEDsInDot<FailLEDsPerDot; LEDsInDot++) {
leds[FailGuestsStartLED + Direction*((FailCounter*FailLEDsPerDot) + LEDsInDot)] = FailColors[FailCounter];
}
}
FastLED.show();
}
void SetTime(int Minutes, int Seconds, CRGB TimeColor) {
int Tens;
SetTimeColon(TimeColor);
Tens = Minutes/10;
SetDigit(StartLEDMinutes10, TimeColor, Tens);
SetDigit(StartLEDMinutes1, TimeColor, Minutes - (Tens*10) );
Tens = Seconds/10;
SetDigit(StartLEDSeconds10, TimeColor, Tens);
SetDigit(StartLEDSeconds1, TimeColor, Seconds - (Tens*10) );
}
void SetTimeColon(CRGB ColonColor) {
for(int i=StartLEDSecondsSeparator; i<StartLEDSecondsSeparator+TimeSeparatorSize; i++) {
leds[i]=ColonColor;
}
}
void SetPeriod(int StartLED, CRGB PeriodColor, int Period) {
if(Period<0) {
SetDigit(StartLED, CRGB::Black, Period);
} else {
SetDigit(StartLED, PeriodColor, Period);
}
}
void SetScore(int HomeScore, CRGB HomeScoreColor, int GuestScore, CRGB GuestScoreColor) {
SetScoreNumber(HomeScore, HomeScoreColor, StartLEDScoreHome100, StartLEDScoreHome10, StartLEDScoreHome1);
SetScoreNumber(GuestScore, GuestScoreColor, StartLEDScoreGuests100, StartLEDScoreGuests10, StartLEDScoreGuests1);
}
void SetScoreNumber(int Score, CRGB ScoreColor, int Start100, int Start10, int Start1) {
int Tens; // make sure we capture the integer part of division by 10
// Deal with home score
// 100's - First digit (either "1" or invisible)
SetScore100( Start100, ScoreColor, Score);
// 10's - Second digit (if applicable)
if(Score>99) { Score = Score-100; }
if(Score>=10) {
Tens = Score/10;
SetDigit(Start10, ScoreColor, Tens);
} else {
Tens = 0;
SetDigitDark(Start10);
}
// 1's
Score = Score-(10*Tens);
SetDigit(Start1, ScoreColor, Score);
}
void SetScore100(int StartLED, CRGB NumberColor, int Score) {
if(Score<100) { NumberColor = CRGB::Black; } // do not show the 100 digit is score less than 100
for(int i=0; i<(2*SegmentVSize); i++) {
leds[StartLED+i] = NumberColor;
}
}
void SetDigit(int StartLED, CRGB DigitColor, int DigitValue) {
SetDigitDark(StartLED); // set LED to dark, do not make this change visible yet (avoid flicker)
if( SegmentNumbers[DigitValue][0]==1 ) { SetSegment(StartLED+SegmentA, SegmentHSize, DigitColor); } // A = horizontal
if( SegmentNumbers[DigitValue][1]==1 ) { SetSegment(StartLED+SegmentB, SegmentVSize, DigitColor); } // B = vertical
if( SegmentNumbers[DigitValue][2]==1 ) { SetSegment(StartLED+SegmentC, SegmentVSize, DigitColor); } // C = vertical
if( SegmentNumbers[DigitValue][3]==1 ) { SetSegment(StartLED+SegmentD, SegmentHSize, DigitColor); } // D = horizontal
if( SegmentNumbers[DigitValue][4]==1 ) { SetSegment(StartLED+SegmentE, SegmentVSize, DigitColor); } // E = vertical
if( SegmentNumbers[DigitValue][5]==1 ) { SetSegment(StartLED+SegmentF, SegmentVSize, DigitColor); } // F = vertical
if( SegmentNumbers[DigitValue][6]==1 ) { SetSegment(StartLED+SegmentG, SegmentHSize, DigitColor); } // G = horizontal
}
void SetDigitDark(int StartLED) {
for(int i=StartLED; i<( StartLED+(3*SegmentHSize)+(4*SegmentVSize) );i++) { // Number has 3 Horizontal and 4 vertical segments
leds[StartLED+i] = CRGB::Black;
}
}
void SetSegment(int StartLED, int LEDCount, CRGB SegmentColor) {
for(int i=0; i<LEDCount; i++) {
leds[StartLED+i] =SegmentColor;
}
}
/* Standard: ABCDEFGH
00 A
40 08
F B
42 G
32 16
E C
24 D
#define SegmentA 0
#define SegmentB 8
#define SegmentC 16
#define SegmentD 24
#define SegmentE 32
#define SegmentF 40
#define SegmentG 48
#define SegmentB 56 */