/*
3D Led Cube Planes FastLED example
Copyright (C) 2020 Uri Shaked.
This code is an example of a FastLED program that controls a 3D LED cube. It uses the FastLED library
to control the LEDs.
The cube size is defined as 6, and the LEDs are connected to pin 3.
The LED brightness is set to 255.
The program initializes the FastLED library and sets up the serial
communication. In the main loop, the code updates the LED colors
every 20 milliseconds.
Within the loop, the LEDs array is cleared, and a nested
loop iterates over the x, y, and z coordinates of the cube.
The variable "counter" is used to control the position of the
LEDs in each plane. The variable "plane" determines the orientation
of the LEDs in each iteration. The hue value is incremented to
change the color of the LEDs.
After updating the LED colors, the FastLED library's show()
function is called to update the physical LEDs.
Overall, this program animates the LED cube by cycling through
different planes and changing the color of the LEDs.
यह कोड एक फास्टएलईडी प्रोग्राम का एक उदाहरण है जो 3 डी एलईडी क्यूब को नियंत्रित करता है।
यह एलईडी को नियंत्रित करने के लिए फास्टएलईडी लाइब्रेरी का उपयोग करता है।
घन आकार को 6 के रूप में परिभाषित किया गया है, और एलईडी पिन 3 से जुड़े हैं।
एलईडी ब्राइटनेस 255 पर सेट है।
कार्यक्रम फास्टएलईडी लाइब्रेरी को प्रारंभ करता है और सीरियल संचार सेट करता है।
मुख्य लूप में, कोड हर 20 मिलीसेकंड में एलईडी रंगों को अपडेट करता है।
लूप के भीतर, एलईडी सरणी को साफ किया जाता है, और क्यूब के एक्स, वाई और जेड
निर्देशांक पर एक नेस्टेड लूप होता है। चर "काउंटर" का उपयोग प्रत्येक विमान में एलईडी
की स्थिति को नियंत्रित करने के लिए किया जाता है। चर "विमान" प्रत्येक पुनरावृत्ति में एलईडी
के अभिविन्यास को निर्धारित करता है। एलईडी के रंग को बदलने के लिए रंग मान में वृद्धि की जाती है।
एलईडी रंगों को अपडेट करने के बाद, भौतिक एलईडी को अपडेट करने के लिए फास्टएलईडी
लाइब्रेरी के शो () फ़ंक्शन को बुलाया जाता है।
कुल मिलाकर, यह कार्यक्रम विभिन्न विमानों के माध्यम से साइकिल चलाकर और एलईडी के
रंग को बदलकर एलईडी क्यूब को एनिमेट करता है।
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(20) {
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();
}
}
FPS: 0
Power: 0.00W
Power: 0.00W