/*
3D Led Cube Planes FastLED example
Copyright (C) 2020 Uri Shaked.
Released under the terms of the MIT license.
*/
#include "FastLED.h"
// Cube size
#define SIZE 8
// LEDs pin
#define DATA_PIN 3
// LED brightness
#define BRIGHTNESS 255
#define NUM_LEDS SIZE * SIZE * SIZE
CRGB leds[NUM_LEDS];
uint32_t counter = 0;
uint32_t plane = 0;
uint16_t prev[SIZE * SIZE] = {0};
byte hue = 0;
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(115200);
}
void loop() {
EVERY_N_MILLISECONDS(10) {
memset(leds, 0, sizeof(leds));
for (uint8_t i = 0; i < SIZE; i++) {
for (uint8_t j = 0; j < SIZE; j++) {
int o = counter / (j + 1);
if (o < 0) {
o = 0;
}
if (o >= SIZE) {
o = SIZE - 1;
}
uint8_t x, y, z;
switch (plane) {
case 0: x = i; y = j; z = o; break;
case 1: x = i; y = j; z = SIZE - 1 - o; break;
case 2: x = i; z = j; y = o; break;
case 3: x = i; z = j; y = SIZE - 1 - o; break;
case 4: z = i; y = j; x = o; break;
case 5: z = i; y = j; x = SIZE - 1 - o; break;
}
leds[z * SIZE * SIZE + y * SIZE + x] = CHSV(hue, 255, 255);
}
}
counter++;
if (counter == SIZE * SIZE) {
counter = 0;
plane = (plane + 1) % 6;
hue += 16;
}
FastLED.show();
}
}