Skip to content

Instantly share code, notes, and snippets.

@inges
Created September 4, 2013 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inges/0b9b19c33188bfc53a96 to your computer and use it in GitHub Desktop.
Save inges/0b9b19c33188bfc53a96 to your computer and use it in GitHub Desktop.
Tetrahoden / Version vom "De fofftig Penns"-Auftritt beim Pixxen-Festival 2013
// Libraries
#include <FastSPI_LED2.h>
#include <SerialCommand.h>
// Seitenzugriff ueber Konstanten
#define SIDE_LEFT 0
#define SIDE_RIGHT 1
#define SIDE_BACK 2
#define SIDE_ALL 3
// Richtungskonstanten
#define DIRECTION_TTB 0
#define DIRECTION_LTR 1
#define DIRECTION_RTL 2
// Anzahl und Positionen der LEDs
#define NUM_LEDS 63
#define NUM_LEDS_ONE_SIDE 21
#define NUM_LEDS_BORDER 6
#define NUM_LEDS_BORDERS 15
#define NUM_LEDS_START_LEFT 0
#define NUM_LEDS_STOP_LEFT 20
#define NUM_LEDS_START_RIGHT 21
#define NUM_LEDS_STOP_RIGHT 41
#define NUM_LEDS_START_BACK 42
#define NUM_LEDS_STOP_BACK 62
int led_start = NUM_LEDS_START_LEFT;
int led_stop = NUM_LEDS_STOP_LEFT;
// LED-Positionen der Kanten (seitenweise)
int ledsBordersLeft[] = {0,1,5,6,14,15,16,17,18,19,20,10,9,3,2};
int ledsBordersRight[] = {41,40,36,35,27,26,25,24,23,22,21,31,32,38,39};
int ledsBordersBack[] = {42,43,44,47,45,48,51,56,52,62,57,61,58,60,59};
int ledsBordersAll[] = {0,1,5,6,14,15,16,17,18,19,20,10,9,3,2, 41,40,36,35,27,26,25,24,23,22,21,31,32,38,39, 42,43,44,47,45,48,51,56,52,62,57,61,58,60,59};
// LED-Positionen fuer Buchstaben und Ziffern
int ledsLetters[][21] = {
{1,2,5,3,6,7,8,9,14,10}, // 0 = A
{1,2,5,3,6,7,8,13,11,17,18}, // 1 = B
{1,2,5,3,6,13,11,17,18}, // 2 = C
{1,2,5,3,7,9,13,11,17,18}, // 3 = D
{1,2,5,6,7,8,13,17,18}, // 4 = E
{1,2,5,6,7,8,13,17}, // 5 = F
{1,2,5,6,8,9,13,11,17,18}, // 6 = G
{1,5,3,6,7,8,9,13,11,18}, // 7 = H
{1,2,4,7,8,12,17,18}, // 8 = I
{2,3,9,13,11,17,18}, // 9 = J
{1,5,3,7,8,13,11,17,19}, // 10 = K
{1,5,7,13,17,18,19}, // 11 = L
{5,3,6,7,8,9,14,12,10,15,20}, // 12 = M
{5,6,7,9,14,12,11,15,18}, // 13 = N
{1,2,5,3,6,9,13,11,17,18}, // 14 = O
{1,2,5,3,7,8,13,16}, // 15 = P
{1,2,5,3,6,9,13,11,17,18,19}, // 16 = Q
{1,2,5,3,6,7,8,14,11,15,19}, // 17 = R
{2,1,5,7,8,11,18,17}, // 18 = S
{5,4,3,7,12,17}, // 19 = T
{5,3,6,9,13,11,17,18}, // 20 = U
{5,7,9,12,11,18}, // 21 = V
{5,3,6,9,13,12,11,17,18}, // 22 = W
{5,3,7,8,12,11,17,19}, // 23 = X
{5,3,7,8,12,17}, // 24 = Y
{5,4,3,8,12,17,18,19}, // 25 = Z
{}, // 26 = LEERZEICHEN
{1,2,5,3,6,9,13,11,17,18}, // 27 = 0
{1,2,4,7,8,12,17,18}, // 28 = 1
{1,2,5,3,8,12,17,18,19}, // 29 = 2
{1,2,3,7,8,11,17,18}, // 30 = 3
{0,1,5,6,7,8,9,12,17}, // 31 = 4
{1,2,5,6,7,8,11,17,18}, // 32 = 5
{1,2,5,6,7,8,13,11,17,18}, // 33 = 6
{5,4,3,8,12,17}, // 34 = 7
{1,2,5,3,7,8,13,11,17,18}, // 35 = 8
{1,2,5,3,6,7,8,9,11,17,18}, // 36 = 9
};
// Hilfsarray fuer die Darstellung von Buchstaben und Ziffern
int letterLength[] = {
10, // A
11, // B
9, // C
10, // D
9, // E
8, // F
10, // G
10, // H
8, // I
7, // J
9, // K
7, // L
11, // M
9, // N
10, // O
8, // P
11, // Q
11, // R
8, // S
6, // T
8, // U
6, // V
9, // W
8, // X
6, // Y
8, // Z
0, // LEERZEICHEN
10, // 0
8, // 1
9, // 2
8, // 3
10, // 4
9, // 5
10, // 6
6, // 7
10, // 8
11, // 9
};
// LED-Positionen fuer jede einzelne der 9 Kanten
int ledsBorders[9][6] = {
{15,14,6,5,1,0},
{0,2,3,9,10,20},
{20,19,18,17,16,15},
{21,31,32,38,39,41},
{41,40,36,35,27,26},
{26,25,24,23,22,21},
{57,56,48,47,43,42},
{42,44,45,51,52,62},
{62,61,60,59,58,57},
};
// LED-Positionen der Reihen von oben nach unten (ein- auf dreiseitig)
int ledsRowsTTB[6][6] = {
{0},
{1,2},
{5,4,3},
{6,7,8,9},
{14,13,12,11,10},
{15,16,17,18,19,20},
};
// LED-Positionen der Reihen von links nach rechts (ein- auf dreiseitig)
int ledsRowsLTR[6][6] = {
{15},
{14,16},
{6,13,17},
{5,7,12,18},
{1,4,8,11,19},
{0,2,3,9,10,20},
};
// LED-Positionen der Reihen von rechts nach links (ein- auf dreiseitig)
int ledsRowsRTL[6][6] = {
{20},
{10,19},
{9,11,18},
{3,8,12,17},
{2,4,7,13,16},
{0,1,5,6,14,15},
};
// LED-Positionen der Reihen von innen nach aussen (ein- auf dreiseitig)
int ledsInnerouter[4][9] = {
{7,8,12},
{5,4,3,6,9,13,11,17,18},
{1,2,14,10,16,19},
{0,15,20}
};
// Hilfsarray fuer die Umsetzung einseitiger Positionen auf die beiden anderen Seiten
int ledsLeftToRight[] = {41,39,40,36,37,38,32,33,34,35,27,28,29,30,31,21,22,23,24,25,26};
int ledsLeftToBack[] = {42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62};
// Anzahl der durchlaufenen Gesamt-Loops initialisieren
int loopCount = 0;
// Hilfskonstanten
int BOTTOM_INDEX = 0;
int TOP_INDEX = int(NUM_LEDS/2);
int EVENODD = NUM_LEDS%2;
struct CRGB leds[NUM_LEDS];
int ledsX[NUM_LEDS][3]; //-ARRAY FOR COPYING WHATS IN THE LED STRIP CURRENTLY (FOR CELL-AUTOMATA, ETC)
SerialCommand sCmd; //-SETUP SerialCommand OBJECT
int ledMode = 999; // Genereller Modus / Es gibt derzeit keine weiteren
//-PERSISTENT VARS
int idex = 0; //-LED INDEX (0 to NUM_LEDS-1
int idx_offset = 0; //-OFFSET INDEX (BOTTOM LED TO ZERO WHEN LOOP IS TURNED/DOESN'T REALLY WORK)
int ihue = 0; //-HUE (0-360)
int ibright = 0; //-BRIGHTNESS (0-255)
int isat = 0; //-SATURATION (0-255)
int bouncedirection = 0; //-SWITCH FOR COLOR BOUNCE (0-1)
float tcount = 0.0; //-INC VAR FOR SIN LOOPS
int lcount = 0; //-ANOTHER COUNTING VAR
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//------------------SETUP------------------
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
void setup()
{
Serial.begin(9600); // SETUP HARDWARE SERIAL (USB)
LEDS.setBrightness(222); // SET BRIGHTNESS
//---Put ws2801 strip on the hardware SPI pins with a BGR ordering of rgb and limited to a 1Mhz data rate
//LEDS.addLeds<WS2801, 11, 13, BGR, DATA_RATE_MHZ(1)>(leds, NUM_LEDS);
LEDS.addLeds<WS2801, RBG>(leds, NUM_LEDS);
sCmd.addCommand("m", set_mode_strip);
sCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
one_color_all(0,0,0); //-BLANK STRIP
LEDS.show();
Serial.println("---SETUP COMPLETE---");
}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//------------------MAIN LOOP------------------
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
void loop() {
sCmd.readSerial(); //-PROCESS SERIAL COMMANDS
// if (ledMode == 0) {one_color_all(0,0,0);} //---STRIP OFF - "0"
if (ledMode == 999) {ot2013_mode();}
}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// ------------------------ LIGHTSHOWS ------------------------
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
void ot2013_mode(){
loopCount++;
set_leds_off();
int r = 1;
// Countdown
if (loopCount == 1) {
// words(0,1000); // Countdown
// words(2,1000); // OMA LEBT
}
// Einmal noch flickern
for(int i=0; i<r*100; i++) {flicker(0, 255);}
for(int i=0; i<r*100; i++) {flicker(50, 255);}
for(int i=0; i<r*100; i++) {flicker(100, 255);}
for(int i=0; i<r*100; i++) {flicker(150, 255);}
for(int i=0; i<r*100; i++) {flicker(200, 255);}
for(int i=0; i<r*100; i++) {flicker(250, 255);}
for(int i=0; i<r*100; i++) {flicker(300, 255);}
// leuchtende Kanten
light_border(255,255,255,0,140,40);
light_border(255,255,255,0,130,40);
light_border(255,255,255,0,120,40);
light_border(255,255,255,0,110,40);
light_border(255,255,255,0,100,40);
light_border(255,255,255,0,90,40);
light_border(255,255,255,SIDE_ALL,140,80);
light_border(255,255,255,SIDE_ALL,110,80);
light_border(255,255,255,SIDE_ALL,80,80);
// laufende Dreiecke, weiß
for(int i=0; i<r*10; i++) {
set_leds_off();
running_innerouter(255,255,255,120);
}
// laufende, einzelne Reihen, weiß
for(int i=0; i<r*3; i++) {running_rows(255,255,255,150,DIRECTION_TTB);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,150,DIRECTION_LTR);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,150,DIRECTION_RTL);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,120,DIRECTION_TTB);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,120,DIRECTION_LTR);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,120,DIRECTION_RTL);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,90,DIRECTION_TTB);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,90,DIRECTION_LTR);}
for(int i=0; i<r*3; i++) {running_rows(255,255,255,90,DIRECTION_RTL);}
// laufende Reihen, weiß
for(int i=0; i<r*17; i++) {
set_leds_off();
running_rows_hold(255,255,255,50,DIRECTION_TTB);
running_rows_hold(0,0,0,50,DIRECTION_TTB);
}
// laufende Reihen, bunt
for(int i=0; i<r*17; i++) {
set_leds_off();
running_rows_rainbow(50,DIRECTION_TTB);
running_rows_hold(0,0,0,50,DIRECTION_TTB);
}
// Einmal noch flickern
for(int i=0; i<r*300; i++) {flicker(200, 255);}
// einfarbige Seiten im Wechsel
// vollflächige Farbeffekte
for(int i=0; i<r*10; i++) {one_color_all(255,255,255);}
for(int i=0; i<r*200; i++) {rainbow_fade(20);}
for(int i=0; i<r*200; i++) {rainbow_loop(10, 20);}
for(int i=0; i<r*200; i++) {random_burst(20);}
for(int i=0; i<r*500; i++) {color_bounceFADE(20);}
for(int i=0; i<r*500; i++) {random_march(30);}
for(int i=0; i<r*250; i++) {rwb_march(80);}
for(int i=0; i<r*100; i++) {rainbow_vertical(15, 50);}
for(int i=0; i<r*100; i++) {strip_march_ccw(100);}
for(int i=0; i<r*100; i++) {strip_march_cw(100);}
// Knight Rider Lauflicht
// for(int i=0; i<r*10; i++) {light_borders(255,255,255,SIDE_ALL);}
// for(int i=0; i<r*50; i++) {running_rows(50);}
// for(int i=0; i<r*3; i++) {light_border(255,255,255,0,200,100);}
// for(int i=0; i<r*1; i++) {words(1,1000);} // Omas Teich 2013
// for(int i=0; i<r*5; i++) {light_border(255,255,255,0,100,100);}
// for(int i=0; i<r*10; i++) {light_border(255,255,255,SIDE_ALL,100,100);}
// for(int i=0; i<r*10; i++) {light_borders(255,255,255,SIDE_ALL);}
// for(int i=0; i<r*10; i++) {light_borders(255,255,255,SIDE_ALL);}
// for(int i=0; i<r*10; i++) {light_borders(255,0,0,SIDE_LEFT);light_borders(0,255,0,SIDE_RIGHT);light_borders(0,0,255,SIDE_BACK);}
// for(int i=0; i<r*10; i++) {one_color_side(255,0,0,SIDE_LEFT);one_color_side(0,255,0,SIDE_RIGHT);one_color_side(0,0,255,SIDE_BACK);}
}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//------------------------LED EFFECT FUNCTIONS------------------------
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//-SET ALL LEDS TO OFF
void set_leds_off() {
for(int i = 0 ; i < NUM_LEDS; i++ ) {
set_color_led(i, 0, 0, 0);
}
LEDS.show();
delay(1);
}
// anhand der LED-Position auf der linken Seite auch beide anderen Seiten leuchten lassen
void set_color_led_lrb(int ledLeft, int cred, int cgrn, int cblu) {
set_color_led(ledLeft, cred, cgrn, cblu);
set_color_led(ledsLeftToRight[ledLeft], cred, cgrn, cblu);
set_color_led(ledsLeftToBack[ledLeft], cred, cgrn, cblu);
}
// eine komplette Reihe leuchten lassen
void set_color_led_row(int irow, int idirection, int cred, int cgrn, int cblu) {
int ledNow = 0;
for(int j = 0 ; j <= irow; j++ ) {
switch (idirection) {
case DIRECTION_TTB:
ledNow = ledsRowsTTB[irow][j];
break;
case DIRECTION_LTR:
ledNow = ledsRowsLTR[irow][j];
break;
case DIRECTION_RTL:
ledNow = ledsRowsRTL[irow][j];
break;
}
set_color_led_lrb(ledNow, cred, cgrn, cblu);
}
}
// einen der drei LED-Bloecke von inne nach außen leuchten lassen
void set_color_led_innerouter(int irow, int cred, int cgrn, int cblu) {
int jMax = 0;
switch (irow) {
case 0:
jMax = 3;
break;
case 1:
jMax = 9;
break;
case 2:
jMax = 6;
break;
case 3:
jMax = 3;
break;
}
int ledNow = 0;
for(int j = 0 ; j < jMax; j++ ) {
ledNow = ledsInnerouter[irow][j];
set_color_led_lrb(ledNow, cred, cgrn, cblu);
}
}
// Lauflicht, farbig, Reihen von oben nach unten
void running_innerouter(int cred, int cgrn, int cblu, int idelay) {
for(int j = 0 ; j < 4; j++ ) {
set_leds_off();
set_color_led_innerouter(j, cred, cgrn, cblu);
LEDS.show();
delay(idelay);
}
}
// Lauflicht, farbig, Reihen von oben nach unten
void running_rows(int cred, int cgrn, int cblu, int idelay, int idirection) {
for(int j = 0 ; j < 6; j++ ) {
set_leds_off();
set_color_led_row(j, idirection, cred, cgrn, cblu);
LEDS.show();
delay(idelay);
set_leds_off();
}
}
// Lauflicht, farbig, Reihen von oben nach unten, einfaerben, loeschen
void running_rows_hold(int cred, int cgrn, int cblu, int idelay, int idirection) {
for(int j = 0 ; j < 6; j++ ) {
set_color_led_row(j, idirection, cred, cgrn, cblu);
LEDS.show();
delay(idelay);
}
}
// Lauflicht, regenbogenfarbig, Reihen von oben nach unten, einfaerben, loeschen
void running_rows_rainbow(int idelay, int idirection) {
int cred = 255;
int cgrn = 255;
int cblu = 255;
for(int j = 0 ; j < 6; j++ ) {
switch (j) {
case 0:
cred = 255;
cgrn = 0;
cblu = 0;
break;
case 1:
cred = 255;
cgrn = 127;
cblu = 0;
break;
case 2:
cred = 255;
cgrn = 255;
cblu = 0;
break;
case 3:
cred = 0;
cgrn = 255;
cblu = 0;
break;
case 4:
cred = 0;
cgrn = 0;
cblu = 255;
break;
case 5:
cred = 75;
cgrn = 0;
cblu = 130;
break;
}
set_color_led_row(j, idirection, cred, cgrn, cblu);
LEDS.show();
delay(idelay);
}
}
// SHOW ONE LETTER
void showLetter(int iletter, int idelay) {
set_leds_off();
int ledNow = 0;
int ledNowRight = 0;
int letterLengthNow = letterLength[iletter];
for(int j = 0 ; j < letterLengthNow; j++ ) {
ledNow = ledsLetters[iletter][j];
set_color_led_lrb(ledNow, 255, 255, 255);
}
LEDS.show();
delay(idelay);
}
// SHOW ALLE LETTERS
void alphabet() {
for(int i = 0 ; i < 37; i++ ) {
showLetter(i,1000);
}
}
void words(int iword, int idelay) {
int wordLetters[][50] = {
{36,35,34,33,32,31,30,29,28,27}, // 9876543210
{14,12,0,18, 26, 19,4,8,2,7, 26, 29,27,28,30}, // OMAS TEICH 2013
{14,12,0, 26, 11,4,1,19}, // OMA LEBT
};
int wordCounts[] = {
10, // 9876543210
15, // OMAS TEICH 2013
};
for(int i = 0 ; i < wordCounts[iword]; i++ ) {
showLetter(wordLetters[iword][i],idelay);
}
}
void one_color_side(int cred, int cgrn, int cblu, int side, int idelay) {
if (side == SIDE_ALL) {
led_start = NUM_LEDS_START_LEFT;
led_stop = NUM_LEDS_STOP_BACK;
} else if (side == SIDE_LEFT) {
led_start = NUM_LEDS_START_LEFT;
led_stop = NUM_LEDS_STOP_LEFT;
} else if (side == SIDE_RIGHT) {
led_start = NUM_LEDS_START_RIGHT;
led_stop = NUM_LEDS_STOP_RIGHT;
} else {
led_start = NUM_LEDS_START_BACK;
led_stop = NUM_LEDS_STOP_BACK;
}
for(int i = led_start ; i <= led_stop; i++ ) {
set_color_led(i, cred, cgrn, cblu);
}
LEDS.show();
delay(idelay);
}
void light_borders(int cred, int cgrn, int cblu, int side) {
if (side == SIDE_LEFT) {
for(int i = 0 ; i < NUM_LEDS_BORDERS; i++ ) {
set_color_led(ledsBordersLeft[i], cred, cgrn, cblu);
LEDS.show();
delay(1);
}
} else if (side == SIDE_RIGHT) {
for(int i = 0 ; i < NUM_LEDS_BORDERS; i++ ) {
set_color_led(ledsBordersRight[i], cred, cgrn, cblu);
LEDS.show();
delay(1);
}
} else if (side == SIDE_BACK) {
for(int i = 0 ; i < NUM_LEDS_BORDERS; i++ ) {
set_color_led(ledsBordersBack[i], cred, cgrn, cblu);
LEDS.show();
delay(1);
}
} else {
for(int i = 0 ; i < NUM_LEDS_BORDERS; i++ ) {
set_color_led(ledsBordersLeft[i], cred, cgrn, cblu);
set_color_led(ledsBordersRight[i], cred, cgrn, cblu);
set_color_led(ledsBordersBack[i], cred, cgrn, cblu);
LEDS.show();
delay(30);
set_color_led(ledsBordersLeft[i], 0,0,0);
set_color_led(ledsBordersRight[i], 0,0,0);
set_color_led(ledsBordersBack[i], 0,0,0);
LEDS.show();
delay(10);
}
}
}
void light_border(int cred, int cgrn, int cblu, int side, int idelay, int times) { //-JUST THE BORDERS
for(int j = 0 ; j < times; j++ ) {
set_leds_off();
if (side == SIDE_ALL) {
int borderNowLeft = random(0,3);
int borderNowRight = borderNowLeft + 3;
int borderNowBack = borderNowLeft + 6;
for(int i = 0 ; i < 6; i++ ) {
set_color_led(ledsBorders[borderNowLeft][i], cred, cgrn, cblu);
set_color_led(ledsBorders[borderNowRight][i], cred, cgrn, cblu);
set_color_led(ledsBorders[borderNowBack][i], cred, cgrn, cblu);
}
} else {
int borderNow = random(0,9);
for(int i = 0 ; i < 6; i++ ) {
set_color_led(ledsBorders[borderNow][i], cred, cgrn, cblu);
}
}
LEDS.show();
delay(idelay);
}
}
void one_color_all(int cred, int cgrn, int cblu) { //-SET ALL LEDS TO ONE COLOR
for(int i = 0 ; i < NUM_LEDS; i++ ) {
set_color_led(i, cred, cgrn, cblu);
LEDS.show();
delay(1);
}
}
void one_color_allNOSHOW(int cred, int cgrn, int cblu) { //-SET ALL LEDS TO ONE COLOR
for(int i = 0 ; i < NUM_LEDS; i++ ) {
set_color_led(i, cred, cgrn, cblu);
}
}
void rainbow_fade(int idelay) { //-FADE ALL LEDS THROUGH HSV RAINBOW
ihue++;
if (ihue >= 359) {ihue = 0;}
int thisColor[3];
HSVtoRGB(ihue, 255, 255, thisColor);
for(int idex = 0 ; idex < NUM_LEDS; idex++ ) {
set_color_led(idex,thisColor[0],thisColor[1],thisColor[2]);
}
LEDS.show();
delay(idelay);
}
void rainbow_loop(int istep, int idelay) { //-LOOP HSV RAINBOW
idex++;
ihue = ihue + istep;
int icolor[3];
if (idex >= NUM_LEDS) {idex = 0;}
if (ihue >= 359) {ihue = 0;}
HSVtoRGB(ihue, 255, 255, icolor);
set_color_led(idex, icolor[0], icolor[1], icolor[2]);
LEDS.show();
delay(idelay);
}
void random_burst(int idelay) { //-RANDOM INDEX/COLOR
int icolor[3];
idex = random(0,NUM_LEDS);
ihue = random(0,359);
HSVtoRGB(ihue, 255, 255, icolor);
set_color_led(idex, icolor[0], icolor[1], icolor[2]);
LEDS.show();
delay(idelay);
}
void color_bounceFADE(int idelay) { //-BOUNCE COLOR (SIMPLE MULTI-LED FADE)
if (bouncedirection == 0) {
idex = idex + 1;
if (idex == NUM_LEDS) {
bouncedirection = 1;
idex = idex - 1;
}
}
if (bouncedirection == 1) {
idex = idex - 1;
if (idex == 0) {
bouncedirection = 0;
}
}
int iL1 = adjacent_cw(idex);
int iL2 = adjacent_cw(iL1);
int iL3 = adjacent_cw(iL2);
int iR1 = adjacent_ccw(idex);
int iR2 = adjacent_ccw(iR1);
int iR3 = adjacent_ccw(iR2);
for(int i = 0; i < NUM_LEDS; i++ ) {
if (i == idex) {set_color_led(i, 255, 0, 0);}
else if (i == iL1) {set_color_led(i, 100, 0, 0);}
else if (i == iL2) {set_color_led(i, 50, 0, 0);}
else if (i == iL3) {set_color_led(i, 10, 0, 0);}
else if (i == iR1) {set_color_led(i, 100, 0, 0);}
else if (i == iR2) {set_color_led(i, 50, 0, 0);}
else if (i == iR3) {set_color_led(i, 10, 0, 0);}
else {set_color_led(i, 0, 0, 0);}
}
LEDS.show();
delay(idelay);
}
void flicker(int thishue, int thissat) {
int random_bright = random(0,255);
int random_delay = random(10,100);
int random_bool = random(0,random_bright);
int thisColor[3];
if (random_bool < 10) {
HSVtoRGB(thishue, thissat, random_bright, thisColor);
for(int i = 0 ; i < NUM_LEDS; i++ ) {
set_color_led(i, thisColor[0], thisColor[1], thisColor[2]);
}
LEDS.show();
delay(random_delay);
}
}
void random_march(int idelay) { //RANDOM MARCH CCW
copy_led_array();
int iCCW;
int acolor[3];
HSVtoRGB(random(0,360), 255, 255, acolor);
leds[0].r = acolor[0];
leds[0].g = acolor[1];
leds[0].b = acolor[2];
for(int i = 1; i < NUM_LEDS ; i++ ) { //-GET/SET EACH LED COLOR FROM CCW LED
iCCW = adjacent_ccw(i);
leds[i].r = ledsX[iCCW][0];
leds[i].g = ledsX[iCCW][1];
leds[i].b = ledsX[iCCW][2];
}
LEDS.show();
delay(idelay);
}
void rwb_march(int idelay) { //R,W,B MARCH CCW
copy_led_array();
int iCCW;
idex++;
if (idex > 2) {idex = 0;}
switch (idex) {
case 0:
leds[0].r = 255;
leds[0].g = 0;
leds[0].b = 0;
break;
case 1:
leds[0].r = 255;
leds[0].g = 255;
leds[0].b = 255;
break;
case 2:
leds[0].r = 0;
leds[0].g = 0;
leds[0].b = 255;
break;
}
for(int i = 1; i < NUM_LEDS; i++ ) { //-GET/SET EACH LED COLOR FROM CCW LED
iCCW = adjacent_ccw(i);
leds[i].r = ledsX[iCCW][0];
leds[i].g = ledsX[iCCW][1];
leds[i].b = ledsX[iCCW][2];
}
LEDS.show();
delay(idelay);
}
void strip_march_cw(int idelay) { //-MARCH STRIP C-W
copy_led_array();
int iCCW;
for(int i = 0; i < NUM_LEDS; i++ ) { //-GET/SET EACH LED COLOR FROM CCW LED
iCCW = adjacent_ccw(i);
leds[i].r = ledsX[iCCW][0];
leds[i].g = ledsX[iCCW][1];
leds[i].b = ledsX[iCCW][2];
}
LEDS.show();
delay(idelay);
}
void strip_march_ccw(int idelay) { //-MARCH STRIP C-W
copy_led_array();
int iCW;
for(int i = 0; i < NUM_LEDS; i++ ) { //-GET/SET EACH LED COLOR FROM CCW LED
iCW = adjacent_cw(i);
leds[i].r = ledsX[iCW][0];
leds[i].g = ledsX[iCW][1];
leds[i].b = ledsX[iCW][2];
}
LEDS.show();
delay(idelay);
}
void rainbow_vertical(int istep, int idelay) { //-RAINBOW 'UP' THE LOOP
idex++;
if (idex > TOP_INDEX) {idex = 0;}
ihue = ihue + istep;
if (ihue > 359) {ihue = 0;}
// Serial.println(ihue);
int idexA = idex;
int idexB = horizontal_index(idexA);
int acolor[3];
HSVtoRGB(ihue, 255, 255, acolor);
set_color_led(idexA, acolor[0], acolor[1], acolor[2]);
set_color_led(idexB, acolor[0], acolor[1], acolor[2]);
LEDS.show();
delay(idelay);
}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//------------------------------------- UTILITY FXNS --------------------------------------
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//-SET THE COLOR OF A SINGLE RGB LED
void set_color_led(int adex, int cred, int cblu, int cgrn) { // Bei den Chinastrips muss dieses Mal blau und gruen vertauscht werden
int bdex;
if (idx_offset > 0) { //-APPLY INDEX OFFSET
bdex = (adex + idx_offset) % NUM_LEDS;
}
else {bdex = adex;}
leds[bdex].r = cred;
leds[bdex].g = cgrn;
leds[bdex].b = cblu;
}
//-FIND INDEX OF HORIZONAL OPPOSITE LED
int horizontal_index(int i) {
//-ONLY WORKS WITH INDEX < TOPINDEX
if (i == BOTTOM_INDEX) {return BOTTOM_INDEX;}
if (i == TOP_INDEX && EVENODD == 1) {return TOP_INDEX + 1;}
if (i == TOP_INDEX && EVENODD == 0) {return TOP_INDEX;}
return NUM_LEDS - i;
}
//-FIND INDEX OF ANTIPODAL OPPOSITE LED
int antipodal_index(int i) {
//int N2 = int(NUM_LEDS/2);
int iN = i + TOP_INDEX;
if (i >= TOP_INDEX) {iN = ( i + TOP_INDEX ) % NUM_LEDS; }
return iN;
}
//-FIND ADJACENT INDEX CLOCKWISE
int adjacent_cw(int i) {
int r;
if (i < NUM_LEDS - 1) {r = i + 1;}
else {r = 0;}
return r;
}
//-FIND ADJACENT INDEX COUNTER-CLOCKWISE
int adjacent_ccw(int i) {
int r;
if (i > 0) {r = i - 1;}
else {r = NUM_LEDS - 1;}
return r;
}
//-CONVERT HSV VALUE TO RGB
void HSVtoRGB(int hue, int sat, int val, int colors[3]) {
// hue: 0-359, sat: 0-255, val (lightness): 0-255
int r, g, b, base;
if (sat == 0) { // Achromatic color (gray).
colors[0]=val;
colors[1]=val;
colors[2]=val;
} else {
base = ((255 - sat) * val)>>8;
switch(hue/60) {
case 0:
r = val;
g = (((val-base)*hue)/60)+base;
b = base;
break;
case 1:
r = (((val-base)*(60-(hue%60)))/60)+base;
g = val;
b = base;
break;
case 2:
r = base;
g = val;
b = (((val-base)*(hue%60))/60)+base;
break;
case 3:
r = base;
g = (((val-base)*(60-(hue%60)))/60)+base;
b = val;
break;
case 4:
r = (((val-base)*(hue%60))/60)+base;
g = base;
b = val;
break;
case 5:
r = val;
g = base;
b = (((val-base)*(60-(hue%60)))/60)+base;
break;
}
colors[0]=r;
colors[1]=g;
colors[2]=b;
}
}
void copy_led_array(){
for(int i = 0; i < NUM_LEDS; i++ ) {
ledsX[i][0] = leds[i].r;
ledsX[i][1] = leds[i].g;
ledsX[i][2] = leds[i].b;
}
}
// GETS CALLED BY SERIALCOMMAND WHEN NO MATCHING COMMAND
void unrecognized(const char *command) {
Serial.println("nothin fo ya...");
}
void set_mode_strip() { //-SETS THE MODE (SOME MODES REQUIRE RANDOM STARTS TO WORK RIGHT
char *arg;
arg = sCmd.next();
if (arg != NULL) {
ledMode = atoi(arg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment