//
// election.ino: White circle turning red
// Note: The leds array is big (NUM_LEDS * 3 Bytes). There is very little memory left on
// the Arduino. If you use too much memory, the program will crash.
// Leon Abelmann, November 2023
//
// Do not change this
#include <FastLED.h>
#define LED_PIN 6 // Pin on Arduino connection to LED signal cable
#define NUM_LEDS 1349 // Number of LEDs in string
#define LED_TYPE WS2811 // Type of LEDS in string
#define COLOR_ORDER GRB // Order of colors of LEDs
const int numrows = 8; // Number of virtual rows on ceiling
const int rowlength = 216; // Number of LEDs per virtual row
CRGB leds[NUM_LEDS]; // Array with LEDs.
// Declaration help functions, for easy reading:
void setup();
void copy(CRGB * src, CRGB* dst, int len);
void copy_reverse(CRGB* src, CRGB* dst, int len);
void RowToLeds(int rownumber, CRGB row[rowlength]);
// You can change from here:
// Variables
#define BRIGHTNESS 255 // Maximum brightness of LEDs
#define UPDATES_PER_SECOND 1 // Number of updates per second
int count = 1;
CRGB color = CRGB::White;
// Fill array of leds
void FillLEDs(CRGB color)
{
// imaginary led strips of rowlength (216) leds long.
CRGB row[rowlength]; // Rowlenght is 216
// Fill rownumber (8) rows with the color
// Black all
for (int rownumber = 0; rownumber < numrows; ++rownumber){
for (int i = 0; i < rowlength; ++i) {
row[i] = CRGB::Black;
}
}
int center = round(rowlength/2);
// Center row
int length = round(0.8*rowlength/2);
for (int i = 108 - length; i< 108 + length; ++i){
row[i] = color;
}
RowToLeds(4,row);
// one above and below
// black row first
for (int i = 0; i < rowlength; ++i) {
row[i] = CRGB::Black;
}
length = round(0.7*rowlength/2);
for (int i = 108 - length; i< 108 + length; ++i){
row[i] = color;
}
RowToLeds(3,row);
RowToLeds(5,row);
// next above and below
// black row first
for (int i = 0; i < rowlength; ++i) {
row[i] = CRGB::Black;
}
length = round(0.5*rowlength/2);
for (int i = 108 - length; i< 108 + length; ++i){
row[i] = color;
}
RowToLeds(2,row);
RowToLeds(6,row);
}
void loop()
{ // Fill leds array
if( count < 5){
color = CRGB::White;
}
else{
color = CRGB::Red;
}
count = count + 1;
if(count > 8){count = 0;}
FillLEDs(color);
// Show leds array
FastLED.show();
// Wait
FastLED.delay(1000/ UPDATES_PER_SECOND);
}
// Help functions, do not change ////////////////////////////////////////
// Initialize LED string
void setup() {
// For serial communication. On raspiled.local use screen command
Serial.begin(115200);
Serial.print("election.ino");
delay( 500 ); // power-up safety delay 3000
//Initialze LED array
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>
( leds, NUM_LEDS ).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
// Black all leds
int i = 0;
while (i < NUM_LEDS) {
leds[i] = CRGB::Black;
i = i + 1;
}
FastLED.show();
}
// Copy len elements of src to dst array.
// Make sure the arrays src and dst have at least len elements
void copy(CRGB * src, CRGB* dst, int len) {
memcpy(dst, src, sizeof(CRGB)*len);
}
// Copy len elements of src to dst array in reverse.
// So if src = {0,1,2,3} (len = 4), dst = {3,2,1,0}
// Make sure the arrays src and dst have at least len elements
void copy_reverse(CRGB* src, CRGB* dst, int len) {
for (int i = 0; i < len; i++) {
dst[i] = src[len - i - 1];
}
}
// Convert row desription to actual led array
void RowToLeds(int rownumber, CRGB row[rowlength])
{
switch (rownumber) {
case 0:
// Row 0, from 0-70, 71-142
// First 71 leds of row first part of led string
copy( &row[0] , &leds[0] , 71);
// last 72 leds of row second part of led string
copy( &row[rowlength - 72], &leds[71], 72);
break;
case 1:
// Row 1, from 143 - 196, 197 - 268 but should be filled backwards
// First 72 leds of row first part of led string copied backwards
copy_reverse( &row[0] , &leds[197] , 72);
// Last 54 leds of row second part of led string, copied backwards
copy_reverse( &row[rowlength - 54] , &leds[143] , 54);
break;
case 2:
// Row 2, from 269 - 340, 341 - 412
// First 72 leds of row first part of led string
copy( &row[0] , &leds[269] , 72);
// last 72 leds of row second part of led string
copy( &row[rowlength - 72], &leds[341], 72);
break;
case 3:
// Row 3, from 413 - 628, but should be filled backwards
copy_reverse( &row[0] , &leds[413] , 216);
break;
case 4:
// Row 4, from 629 - 844
copy( &row[0] , &leds[629] , 216);
break;
case 5:
// Row 5, from 845 - 1060, but should be filled backwards
copy_reverse( &row[0] , &leds[845] , 216);
break;
case 6:
// Row 6, from 1061 - 1132, 1133 - 1204
// First 72 leds of row first part of led string
copy( &row[0] , &leds[1061] , 72);
// last 72 leds of row second part of led string
copy( &row[rowlength - 72], &leds[1133], 72);
break;
case 7:
// Row 7, from 1205 - 1276, 1277 - 1348 but should be filled backwards
// First 72 leds of row first part of led string copied backwards
copy_reverse( &row[0] , &leds[1277] , 72);
// Last 54 leds of row second part of led string, copied backwards
copy_reverse( &row[rowlength - 72] , &leds[1205] , 72);
break;
}
}