#include <FastLED.h>
#define LED_TYPE WS2811
#define COLOR_ORDER RGB
#define NUM_LEDS_PER_STRIPp 225
#define NUM_STRIPS 15
CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIPp];
#define NUM_LEDS_PER_STRIP 3375
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 1000000
#define SIZE 15
uint8_t brightness = 250;
uint8_t hue = 0;
uint8_t fade = 10;
uint8_t delaytime = 0;
uint16_t delaytime1;
uint16_t delaytime2;
uint16_t delaytime3;
const int width = 15;
const int height = 15;
const int depth = 15;
uint32_t counter = 0;
uint32_t plane = 0;
uint16_t prev[SIZE * SIZE] = {0};
byte die6D=0;
byte die6z=0;
byte xp=0;
byte yp=0;
byte zp=0;
byte xc=0;
byte yc=0;
byte zc=0;
//FUNCTIONS
//xy to led number translation from FastLED extended to z dimension and protected from out of range erwitert um wechsel z
uint16_t XYZ( uint8_t x, uint8_t y, uint8_t z) {
uint16_t i;
if (x < width && y < height && z < depth) {
if ( z & 1) { //ebene gerade
if ( y & 1) { //line gerade
uint8_t reverseY = (height - 1) - y;
i = (reverseY * width) + x; //lines run rückwards
} else {
uint8_t reverseY = (height - 1) - y;
uint8_t reverseX = (width - 1) - x;
i = (reverseY * width) + reverseX; // Odd lines run rückwards und Odd rows run rückwards
}
} else { //ebene ungerade
if ( y & 1) {
// Odd rows run backwards
uint8_t reverseX = (width - 1) - x;
i = (y * width) + reverseX;
} else {
// Even rows run forwards
i = (y * width) + x;// Even rows run forwards
}
}
i = i + (z * width * height);
return i;
} else {
return 0;
}
}
//position and movement variables
int x;
int y;
int z;
int xchange;
int ychange;
int zchange;
void setup() {
FastLED.setMaxPowerInMilliWatts(90000); //max 100W for this power supply
delay(1000);
//FastLED.addLeds<OCTOWS2811>(leds, NUM_LEDS_PER_STRIPp);
FastLED.addLeds<NUM_STRIPS, WS2811, 1>(leds,NUM_LEDS_PER_STRIPp);
FastLED.setBrightness(BRIGHTNESS);
randomSeed(255);
}
void loop() {
//choose random face to "enter" from and starting position on that face,
//and how the line is going to move
if(xp>14)
{
yp++ ;
xp=0;
yc=1;
if(yp>14)
{ yp=0;
//zp++;
}}
if(yp>14)
{
yp=0;
}
if(zp>14)
{ xc=1;
zp=0;
}
x = xp;
y = yp;
z = zp;
xchange = 1;
ychange = 1;
zchange = 1;
while(x>=0 && x<width && y>=0 && y<height && z>=0 && z<depth){
int ledToLight = XYZ(x,y,z);
//int ledToLight = XYZ(x+1,y+1,z+1);
leds[ledToLight] = (CHSV(hue,255,brightness));
FastLED.show();
fadeToBlackBy(leds, NUM_LEDS_PER_STRIP, fade);
x = x + xchange;
y = y + ychange;
z = z + zchange;
delay(1);
}
x = xp;
y = yp;
z = 14;
xchange = 0;
ychange = 0;
zchange = -1;
while(x>=0 && x<width && y>=0 && y<height && z>=0 && z<depth){
int ledToLight = XYZ(x,y,z);
//int ledToLight = XYZ(x+1,y+1,z+1);
leds[ledToLight] = (CHSV(hue,255,brightness));
FastLED.show();
fadeToBlackBy(leds, NUM_LEDS_PER_STRIP, fade);
x = x + xchange;
y = y + ychange;
z = z + zchange;
delay(0);
}
x = xp;
y = yp;
z = zp;
xchange = 0;
ychange = 0;
zchange = 1;
while(x>=0 && x<width && y>=0 && y<height && z>=0 && z<depth){
int ledToLight = XYZ(x,y,z);
//int ledToLight = XYZ(x+1,y+1,z+1);
leds[ledToLight] = (CHSV(hue,255,brightness));
FastLED.show();
fadeToBlackBy(leds, NUM_LEDS_PER_STRIP, fade);
x = x + xchange;
y = y + ychange;
z = z + zchange;
delay(0);
}
x = xp;
y = 0;
z = zp;
xchange = 1;
ychange = 1;
zchange = 0;
while(x>=0 && x<width && y>=0 && y<height && z>=0 && z<depth){
int ledToLight = XYZ(x,y,z);
//int ledToLight = XYZ(x+1,y+1,z+1);
leds[ledToLight] = (CHSV(hue,255,brightness));
FastLED.show();
fadeToBlackBy(leds, NUM_LEDS_PER_STRIP, fade);
x = x + xchange;
y = y + ychange;
z = z + zchange;
delay(0);
}
xp++;
yp++;
//zp++;
die6D++;
hue = hue+10; //move through rainbow every cycle
}