// https://forum.arduino.cc/t/circular-matrix/1164773/6
// https://forum.arduino.cc/t/led-gyro-ball-diy-help/1239872
// https://www.youtube.com/watch?v=Q5d8gTppuYo
// https://www.instructables.com/RGB-LED-Sphere/
// https://youtu.be/DMBejIlcKSM
#include <FastLED.h>
//
#define STRINGS 16
#define STRING_SIZE 16
#define NUM_LEDS (STRINGS * STRING_SIZE)
#define MATRIX_PIN 2
#define BRIGHTNESS 255 // max brightness
//
CRGB leds[NUM_LEDS];
//
//#define BUTTON 3
CRGB pattern1[] = {
CRGB(0xFF, 0xC0, 0xFF),//LIGHT_RED
CRGB(0xFF, 0x00, 0x00),//RED
CRGB(0x80, 0x00, 0x00),//DARK_RED
CRGB(0xCD, 0x5C, 0x5C),//INDIANS RED
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern11[] = {
CRGB(0xC7, 0x15, 0x85),//MediumVioletRed
CRGB(0xFF, 0x45, 0x00),//OrangeRed
CRGB(0xDB, 0x70, 0x93),//PaleVioletRed
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern2[] = {
CRGB(0x80, 0xFF, 0x80),//LIGHT_GREEN
CRGB(0x00, 0xFF, 0x00),//GREEN
CRGB(0x00, 0x80, 0x00),//DARK_GREEN
CRGB(0x55, 0x6B, 0x2F),//DarkOliveGreen
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern22[] = {
CRGB(0x8F, 0xBC, 0x8F),//DarkSeaGreen
CRGB(0x22, 0x8B, 0x22),//ForestGreen
CRGB(0x7C, 0xFC, 0x00),//LawnGreen
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern3[] = {
CRGB(0x80, 0xC0, 0xFF),//LIGHT_BLUE
CRGB(0x00, 0x00, 0xFF),//BLUE
CRGB(0xF0, 0xF8, 0xFF),//AlLICE BLUE
CRGB(0x00, 0x00, 0x80),//DARK_BLUE
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern33[] = {
CRGB(0x00, 0xBF, 0xFF),//DeepSkyBlue
CRGB(0x5F, 0x9E, 0xA0),//CadetBlue
CRGB(0x64, 0x95, 0xED),//CornflowerBlue
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern4[] = {
CRGB(0xFF, 0xFF, 0xE0),//LightYellow
CRGB(0xFF, 0xFF, 0x00),//YELLOW
CRGB(0xFA, 0xFA, 0xD2),//LightGoldenrodYellow
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern5[] = {
CRGB(0x8B, 0x00, 0x8B),//DarkMagenta
CRGB(0xFF, 0x00, 0xFF),//MAGENTA
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern6[] = {
CRGB(0x00, 0xFF, 0xFF),//CYAN
CRGB(0xFF, 0xAF, 0xAF),//PINK
CRGB(0x60, 0x30, 0x00),//BROWN
CRGB(0xFF, 0x80, 0x00),//ORANGE
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
CRGB pattern66[] = {
CRGB(0xC0, 0x00, 0xFF),//PURPLE
CRGB(0x80, 0xFF, 0x00),//LIME
CRGB(0xFF, 0xFF, 0xFF),//WHITE
CRGB(0x00, 0x00, 0x00),//BLACK
};
//
void setup() {
//randomSeed(analogRead(A0)); // allow for pseudo-random colors
Serial.begin(115200);
FastLED.addLeds<WS2812B, MATRIX_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
//pinMode(BUTTON, INPUT_PULLUP);
//Serial.println("Mash the RED button to start.");
//while (digitalRead(BUTTON));
}
//
// void loop() { // DaveX-dial code
// switch (analogRead(A0) * 8 / 1024) {
// case 0: twinkle(); break;
// case 1: pewpew(); break;
// case 2: thealgorithm(); break;
// case 3: circles(); break;
// case 4: swirl_1(); break;
// case 5: swirl_2(); break;
// case 6: onebyone(); break;
// case 7: everyone(); break;
// }
// }
//
void loop() {
//twinkle();
//pewpew();
//thealgorithm();
//circles();
//swirl_3();
//swirl_1();
swirl_2();
//onebyone();
//everyone();
}
//
void twinkle() {
int x = random(NUM_LEDS);
leds[x] = CRGB(255, 0, 0);
FastLED.show();
delay(10);
FastLED.clear();
FastLED.show();
}
//
void swirl_1() {
int i = 0;
for (int j = 0; j < STRINGS; j++) {
int dot = (j * STRING_SIZE) + j + (i * STRINGS);
for (int k = 0; k < STRINGS; k++) {
if (dot + k * STRING_SIZE > STRINGS * STRING_SIZE)
dot = dot - STRINGS * STRING_SIZE;
leds[dot + k * STRING_SIZE] = CRGB(
128 + k * 16, // red
255 - (128 + k * 16), // green
64 + k * 8); // blue
// alto777 code
// leds[dot + k * STRING_SIZE] = CRGB(
// ((sin( 2 * PI * j / NUM_LEDS + 0 * PI / 3 ) * 127 + 128) / 255) * 255,
// ((sin( 2 * PI * j / NUM_LEDS + 2 * PI / 3 ) * 127 + 128) / 255) * 255,
// ((sin( 2 * PI * j / NUM_LEDS + 4 * PI / 3 ) * 127 + 128) / 255) * 255);
}
FastLED.show();
delay(10);
}
// delay(100);
FastLED.clear();
}
//
void swirl_2() {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < STRINGS; j++) {//for( int j= STRINGS - 1; j >= STRINGS; j--) {
int dot = (j * STRING_SIZE) + j + (i * STRINGS);
if (dot + 00 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 00] = pattern1;
if (dot + 16 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 16] = pattern11;
if (dot + 32 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 32] = pattern2;
if (dot + 48 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 48] = pattern22;
if (dot + 64 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 64] = pattern3;
if (dot + 80 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 80] = pattern33;
if (dot + 96 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 96] = pattern4;
if (dot + 112 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 112] = pattern5;
//if (dot + 96 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 96] = pattern6;
//if (dot + 112 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 112] = pattern66;
FastLED.show();
delay(100);
}
}
delay(100);
FastLED.clear();
}
//
void swirl_3() {
for (int i = 0; i < 2; i++) {
for(int j = STRINGS-1; j >= 0; j--) {
int dot = (j * STRING_SIZE) + j + (i * STRINGS);
if (dot + 00 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 00] = pattern1;
if (dot + 16 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 16] = pattern11;
if (dot + 32 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 32] = pattern2;
if (dot + 48 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 48] = pattern22;
if (dot + 64 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 64] = pattern3;
if (dot + 80 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 80] = pattern33;
if (dot + 96 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 96] = pattern4;
if (dot + 112 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 112] = pattern5;
//if (dot + 96 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 96] = pattern6;
//if (dot + 112 > STRINGS * STRING_SIZE) dot = dot - STRINGS * STRING_SIZE; leds[dot + 112] = pattern66;
FastLED.show();
delay(100);
}
}
delay(100);
FastLED.clear();
}
//
void pewpew() {
for (int i = 0; i < STRING_SIZE; i++) {
for (int j = 0; j < STRINGS; j++) {
leds[i + j * 16] = CRGB(255, 255, 255);
FastLED.show();
}
}
delay(10);
FastLED.clear();
}
//
void thealgorithm() {
for (int i = 0; i < STRING_SIZE; i++) {
for (int j = 0; j < STRINGS; j++) {
leds[i + j * (16 + i)] = CRGB(0, 127, 255);
FastLED.show();
delay(10);
}
}
delay(100);
FastLED.clear();
}
//
void circles() {
for (int i = 0; i < STRING_SIZE; i++) {
for (int j = 0; j < STRINGS; j++) {
leds[i + j * STRING_SIZE] = CRGB(255, 0, 255);
FastLED.show();
delay(50);
}
}
delay(10);
FastLED.clear();
}
//
void onebyone() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(random(256), random(256), random(256));
FastLED.show();
}
}
//
void everyone() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(random(256), random(256), random(256));
}
FastLED.show();
}