//#define FASTLED_ESP8266_D1_PIN_ORDER
//#define FASTLED_ALLOW_INTERRUPTS 0
#include "FastLED.h"
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
//FASTLED_USING_NAMESPACE
#include <EEPROM.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Utilizzare qsuba per la colorazione dei pixel uniforme e qsubd per la colorazione dei pixel non uniforme
#define qsubd(x, b) ((x>b)?b:0) // Macro di sottrazione digitale senza segno. se risultato <0, allora => 0. Altrimenti, prendi un valore fisso.
#define qsuba(x, b) ((x>b)?x-b:0) // Macro di sottrazione senza segno analogico. se risultato <0, allora => 0
#define SCREEN_WIDTH 128 // Larghezza del display OLED, in pixel
#define SCREEN_HEIGHT 64 // Altezza del display OLED, in pixel
// Dichiarazione per un display SSD1306 collegato a I2C (SDA, pin SCL)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LED_DT D3
#define COLOR_ORDER GRB
#define LED_TYPE WS2812B
#define NUM_LEDS 30
struct CRGB leds[NUM_LEDS];
#define LED D6
#define BUTTON D7 //Pulsante cambio
volatile int selectedEffect=0;
int nEffect;
char Effetto[][21] = { " rainbow march ", " noise16 3", " confetti pal ", " fill grad ", " fade in ", " three sin pal demo", " rainbow beat ", " plasma ", " palette crossfade", " one sine pal demo", " matrix pal demo" };
// Le variabili globali possono essere modificate al volo.
uint8_t max_bright = 255; // Definizione di luminosità complessiva. Può essere modificato al volo.
uint8_t maxChanges = 24; // Numero di interpolazioni tra le tavolozze.
//-------------------------------
// hanno 3 CRGB indipendenti - 2 per le sorgenti e uno per l'uscita
//CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
//--------------------------------
//--------------------------------
// Palette definitions
CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette;
TBlendType currentBlending; // NOBLEND or LINEARBLEND
// Define variables used by the sequences.
uint8_t thisfade; // How quickly does it fade? Lower = slower fade rate.
int thishue; // Starting hue.
uint8_t thisinc; // Incremental value for rotating hues
uint8_t thissat; // The saturation, where 255 = brilliant colours.
uint8_t thisbri; // Brightness of a sequence. Remember, max_bright is the overall limiter.
int huediff; // Range of random #'s to use for hue
uint8_t thisdelay; // We don't need much delay (if any)
uint8_t thisdiff; // Incremental change in hue between each dot.
uint8_t numdots; // Number of dots in use.
uint8_t curhue; // The current hue
uint8_t thisbright; // How bright should the LED/display be.
uint8_t thisbeat; // Higher = faster movement.
uint8_t thisrot = 1; // You can change how quickly the hue rotates for this wave.
int8_t thisspeed = 8; // You can change the speed of the wave, and use negative values.
uint8_t allfreq = 32; // You can change the frequency, thus distance between bars.
int thisphase = 0; // Phase change value gets calculated.
uint8_t thiscutoff = 128; // You can change the cutoff value to display this wave. Lower value = longer wave.
uint8_t bgclr = 0; // A rotating background colour.
uint8_t bgbright = 0; // Brightness of background colour
uint8_t bgclrinc = 0;
int startIndex = 0;
uint8_t palIndex = 95;
int thisdir = 0;
bool huerot = 0; // Does the hue rotate? 1 = yes
uint8_t bgbri = 0;
//-------------------------------
int wave1 = 0; // Current phase is calculated.
int wave2 = 0;
int wave3 = 0;
uint8_t lvl1 = 80; // Any result below this value is displayed as 0.
uint8_t lvl2 = 80;
uint8_t lvl3 = 80;
uint8_t mul1 = 7; // Frequency, thus the distance between waves
uint8_t mul2 = 6;
uint8_t mul3 = 5;
//-------------------------------
void setup()
{
//if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
//Serial.println(F("SSD1306 allocation failed"));
//while (true); //Non procedere, loop per sempre
//}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
//display.display();
// Clear the buffer
//display.clearDisplay();
//display.setTextSize(2); // Normal 1:1 pixel scale
//display.setTextColor(WHITE); // Draw white text
//display.setCursor(10,1); // Start at top-left corner
// display.println("!effetto!");
////display.clearDisplay();
//display.setTextSize(2); // Normal 1:1 pixel scale
//display.setTextColor(WHITE); // Draw white text
Serial.begin(9600);
//FastLED.addLeds<WS2812, PIN, GRB>(leds, NUM_LEDS); //.setCorrection( TypicalLEDStrip );
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(max_bright);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000); // FastLED Power management set at 5V, 500mA.
currentBlending = LINEARBLEND;
EEPROM.begin(512);
//EEPROM.get(addr,data);
//EEPROM.read(0, selectedEffect);
selectedEffect=EEPROM.read(0);
if (selectedEffect == 5) {
// Initialize global variables for sequences
uint8_t thisdelay = 20; // A delay value for the sequence(s)
/* int wave1 = 0; // Current phase is calculated.
int wave2 = 0;
int wave3 = 0;
uint8_t lvl1 = 80; // Any result below this value is displayed as 0.
uint8_t lvl2 = 80;
uint8_t lvl3 = 80;
uint8_t mul1 = 7; // Frequency, thus the distance between waves
uint8_t mul2 = 6;
uint8_t mul3 = 5;
*/
CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 targetPalette(PartyColors_p);
}
if (selectedEffect == 10) {
thisbright = 255;
thissat = 255;
thisdelay = 50;
max_bright = 255; // Overall brightness definition. It can be changed on the fly.
}
pinMode(BUTTON,INPUT_PULLUP); // internal pull-up resistor
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
attachInterrupt (digitalPinToInterrupt(BUTTON), changeEffect, CHANGE); // pressed
}
int x = 0;
// REPLACE FROM HERE
void loop() {
digitalWrite(LED,LOW);
EEPROM.write(0,selectedEffect);
EEPROM.commit();
Serial.println(selectedEffect);
if(selectedEffect>10) {
selectedEffect=0;
EEPROM.write(0,0);
EEPROM.commit();
}
//display.setCursor(x, 28); // Inizia dall'angolo in alto a sinistra
//display.cp437(true); // Utilizza il carattere "Code Page 437" completo di 256 caratteri
//display.print(Effetto[selectedEffect]);
//display.print(selectedEffect);
//display.display();
switch(selectedEffect) {
case 0 : {
// rainbow march
Serial.println("rainbow_march");
rainbow_march(200, 10);
FastLED.show();
break;
}
case 1 : {
EVERY_N_MILLISECONDS(50) {
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // Blend towards the target palette
}
EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 192, random8(128, 255)), CHSV(random8(), 255, random8(128, 255)));
}
noise16_3();
FastLED.show();
break;
}
case 2 : {
// confetti pal
// Define variables used by the sequences.
thisfade = 8;
thishue = 50;
thisinc = 1;
thissat = 100;
thisbri = 255;
huediff = 256;
thisdelay = 5;
ChangeMe_CP(); // Check the demo loop for changes to the variables.
EVERY_N_MILLISECONDS(100) {
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability.
}
EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
confetti_pal();
}
FastLED.show();
break;
}
case 3 : {
// fill grad
fill_grad();
FastLED.show(); // Power managed display of LED's.
break;
}
case 4 : {
// fadein
EVERY_N_MILLISECONDS(100) { // FastLED based non-blocking FIXED delay.
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability.
}
EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
uint8_t baseC = random8(255); // Use the built-in random number generator as we are re-initializing the FastLED one.
targetPalette = CRGBPalette16(CHSV(baseC + random8(0, 32), 255, random8(128, 255)), CHSV(baseC + random8(0, 32), 255, random8(128, 255)), CHSV(baseC + random8(0, 32), 192, random8(128, 255)), CHSV(baseC + random8(0, 32), 255, random8(128, 255)));
}
fadein();
FastLED.show();
break;
}
case 5 : {
// three sin pal demo
// Initialize global variables for sequences
thisdelay = 20; // A delay value for the sequence(s)
ChangeMe_TS();
uint8_t maxChanges = 24;
EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges);
three_sin(); // Improved method of using non-blocking delay
}
FastLED.show();
break;
}
case 6 : {
// rainbow beat
rainbow_beat();
FastLED.show();
break;
}
case 7 : {
// plasma
max_bright = 255;
currentPalette = OceanColors_p;
EVERY_N_MILLISECONDS(50) { // FastLED based non-blocking delay to update/display the sequence.
plasma();
}
EVERY_N_MILLISECONDS(100) {
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability.
}
EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
uint8_t baseC = random8(); // You can use this as a baseline colour if you want similar hues in the next line.
targetPalette = CRGBPalette16(CHSV(baseC + random8(32), 192, random8(128, 255)), CHSV(baseC + random8(32), 255, random8(128, 255)), CHSV(baseC + random8(32), 192, random8(128, 255)), CHSV(baseC + random8(32), 255, random8(128, 255)));
}
FastLED.show();
break;
}
case 8 : {
// palette crossfade
ChangePalettePeriodically();
// nblendPaletteTowardPalette() will crossfade current palette slowly toward the target palette.
//
// Each time that nblendPaletteTowardPalette is called, small changes
// are made to currentPalette to bring it closer to matching targetPalette.
// You can control how many changes are made in each call:
// - the default of 24 is a good balance
// - meaningful values are 1-48. 1=veeeeeeeery slow, 48=quickest
// - "0" means do not change the currentPalette at all; freeze
EVERY_N_MILLISECONDS(100) {
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges);
}
EVERY_N_MILLISECONDS(thisdelay) {
static uint8_t startIndex = 0;
startIndex += 1; // motion speed
FillLEDsFromPaletteColors(startIndex);
}
FastLED.show();
break;
}
case 9 : {
// one sine pal demo
thisdelay = 30;
ChangeMe_OS();
EVERY_N_MILLISECONDS(100) {
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability.
}
EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
startIndex += thisrot; // Motion speed
one_sine_pal(startIndex);
}
FastLED.show();
break;
}
case 10 : {
// matrix pal demo
ChangeMe_MP();
EVERY_N_MILLISECONDS(100) {
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability.
}
EVERY_N_MILLISECONDS(thisdelay) {
matrix();
}
FastLED.show();
break;
}
}
/*
display.clearDisplay();
display.setTextSize(3); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setCursor(x, 0); // Start at top-left corner
display.cp437(true); // Use full 256 char 'Code Page 437' font
display.print(selectedEffect);
// display.print("Hello!");
//display.print(bme.readTemperature());
display.setTextSize(1);
display.print(" o");
display.setTextSize(3);
display.print("C");
display.setTextSize(1);
display.setCursor(x, 25);
display.print("TEMPERATURA");
display.display();
//delay(300); */
}
ICACHE_RAM_ATTR void changeEffect() {
if (digitalRead (BUTTON) == LOW) {
digitalWrite(LED,HIGH);
selectedEffect++;
EEPROM.write(0, selectedEffect);
EEPROM.commit();
//asm volatile (" jmp 0");
ESP.reset();
}
}
// *************************
// ** LEDEffect Functions **
// *************************
void rainbow_march(uint8_t thisdelay, uint8_t deltahue) { // The fill_rainbow call doesn't support brightness levels.
uint8_t thishue = millis() * (255 - thisdelay) / 255; // To change the rate, add a beat or something to the result. 'thisdelay' must be a fixed value.
// thishue = beat8(50); // This uses a FastLED sawtooth generator. Again, the '50' should not change on the fly.
// thishue = beatsin8(50,0,255); // This can change speeds on the fly. You can also add these to each other.
fill_rainbow(leds, NUM_LEDS, thishue, deltahue); // Use FastLED's fill_rainbow routine.
}
//-----------------------------------------------------------------------------------------------------------------------------
void noise16_3() { // no x/y shifting but scrolling along
uint8_t scale = 1000; // the "zoom factor" for the noise
for (uint16_t i = 0; i < NUM_LEDS; i++) {
uint16_t shift_x = 4223; // no movement along x and y
uint16_t shift_y = 1234;
uint32_t real_x = (i + shift_x) * scale; // calculate the coordinates within the noise field
uint32_t real_y = (i + shift_y) * scale; // based on the precalculated positions
uint32_t real_z = millis() * 2; // increment z linear
uint8_t noise = inoise16(real_x, real_y, real_z) >> 7; // get the noise data and scale it down
uint8_t index = sin8(noise * 3); // map led color based on noise data
uint8_t bri = noise;
leds[i] = ColorFromPalette(currentPalette, index, bri, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
}
}
//-----------------------------------------------------------------------------------------------------------------------------
void confetti_pal() { // random colored speckles that blink in and fade smoothly
// Define variables used by the sequences.
uint8_t thisfade = 8; // How quickly does it fade? Lower = slower fade rate.
int thishue = 50; // Starting hue.
uint8_t thisinc = 1; // Incremental value for rotating hues
uint8_t thissat = 100; // The saturation, where 255 = brilliant colours.
uint8_t thisbri = 255; // Brightness of a sequence. Remember, max_bright is the overall limiter.
int huediff = 256; // Range of random #'s to use for hue
uint8_t thisdelay = 5; // We don't need much delay (if any)
fadeToBlackBy(leds, NUM_LEDS, thisfade); // Low values = slower fade.
int pos = random16(NUM_LEDS); // Pick an LED at random.
leds[pos] = ColorFromPalette(currentPalette, thishue + random16(huediff) / 4, thisbri, currentBlending);
thishue = thishue + thisinc; // It increments here.
}
void ChangeMe_CP() { // A time (rather than loop) based demo sequencer. This gives us full control over the length of each sequence.
uint8_t secondHand = (millis() / 1000) % 15; // IMPORTANT!!! Change '15' to a different value to change duration of the loop.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
if (lastSecond != secondHand) { // Debounce to make sure we're not repeating an assignment.
lastSecond = secondHand;
switch (secondHand) {
case 0: targetPalette = OceanColors_p; thisinc = 1; thishue = 192; thissat = 255; thisfade = 2; huediff = 255; break; // You can change values here, one at a time , or altogether.
case 5: targetPalette = LavaColors_p; thisinc = 2; thishue = 128; thisfade = 8; huediff = 64; break;
case 10: targetPalette = ForestColors_p; thisinc = 1; thishue = random16(255); thisfade = 1; huediff = 16; break; // Only gets called once, and not continuously for the next several seconds. Therefore, no rainbows.
case 15: break; // Here's the matching 15 for the other one.
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void fill_grad() {
uint8_t starthue = beatsin8(5, 0, 255);
uint8_t endhue = beatsin8(7, 0, 255);
if (starthue < endhue) {
fill_gradient(leds, NUM_LEDS, CHSV(starthue, 255, 255), CHSV(endhue, 255, 255), FORWARD_HUES); // If we don't have this, the colour fill will flip around.
}
else {
fill_gradient(leds, NUM_LEDS, CHSV(starthue, 255, 255), CHSV(endhue, 255, 255), BACKWARD_HUES);
}
}
//------------------------------------------------------------------------------------------------------------------------------
void fadein() {
random16_set_seed(535); // The randomizer needs to be re-set each time through the loop in order for the 'random' numbers to be the same each time through.
for (int i = 0; i < NUM_LEDS; i++) {
uint8_t fader = sin8(millis() / random8(10, 20)); // The random number for each 'i' will be the same every time.
leds[i] = ColorFromPalette(currentPalette, i * 20, fader, currentBlending); // Now, let's run it through the palette lookup.
}
random16_set_seed(millis()); // Re-randomizing the random number seed for other routines.
}
//---------------------------------------------------------------------------------------------------------------------------
void three_sin() {
wave1 += beatsin8(10, -4, 4);
wave2 += beatsin8(15, -2, 2);
wave3 += beatsin8(12, -3, 3);
for (int k = 0; k < NUM_LEDS; k++) {
uint8_t tmp = sin8(mul1 * k + wave1) + sin8(mul1 * k + wave2) + sin8(mul1 * k + wave3);
leds[k] = ColorFromPalette(currentPalette, tmp, 255);
}
}
void ChangeMe_TS() {
uint8_t secondHand = (millis() / 1000) % 60;
static uint8_t lastSecond = 99;
if (lastSecond != secondHand) {
lastSecond = secondHand;
CRGB p = CHSV(HUE_PURPLE, 255, 255);
CRGB g = CHSV(HUE_GREEN, 255, 255);
CRGB u = CHSV(HUE_BLUE, 255, 255);
CRGB b = CRGB::Black;
CRGB w = CRGB::White;
switch (secondHand) {
case 0: targetPalette = RainbowColors_p; break;
case 5: targetPalette = CRGBPalette16(u, u, b, b, p, p, b, b, u, u, b, b, p, p, b, b); break;
case 10: targetPalette = OceanColors_p; break;
case 15: targetPalette = CloudColors_p; break;
case 20: targetPalette = LavaColors_p; break;
case 25: targetPalette = ForestColors_p; break;
case 30: targetPalette = PartyColors_p; break;
case 35: targetPalette = CRGBPalette16(b, b, b, w, b, b, b, w, b, b, b, w, b, b, b, w); break;
case 40: targetPalette = CRGBPalette16(u, u, u, w, u, u, u, w, u, u, u, w, u, u, u, w); break;
case 45: targetPalette = CRGBPalette16(u, p, u, w, p, u, u, w, u, g, u, w, u, p, u, w); break;
case 50: targetPalette = CloudColors_p; break;
case 55: targetPalette = CRGBPalette16(u, u, u, w, u, u, p, p, u, p, p, p, u, p, p, w); break;
case 60: break;
}
}
}
//----------------------------------------------------------------------------------------------------------------------------
void rainbow_beat() {
uint8_t beatA = beatsin8(17, 0, 255); // Starting hue
uint8_t beatB = beatsin8(13, 0, 255);
fill_rainbow(leds, NUM_LEDS, (beatA + beatB) / 2, 8); // Use FastLED's fill_rainbow routine.
}
//--------------------------------------------------------------------------------------------------------------------------
void plasma() { // This is the heart of this program. Sure is short. . . and fast.
int thisPhase = beatsin8(6, -64, 64); // Setting phase change for a couple of waves.
int thatPhase = beatsin8(7, -64, 64);
for (int k = 0; k < NUM_LEDS; k++) { // For each of the LED's in the strand, set a brightness based on a wave as follows:
int colorIndex = cubicwave8((k * 23) + thisPhase) / 2 + cos8((k * 15) + thatPhase) / 2; // Create a wave and add a phase change and add another wave with its own phase change.. Hey, you can even change the frequencies if you wish.
int thisBright = qsuba(colorIndex, beatsin8(7, 0, 96)); // qsub gives it a bit of 'black' dead space by setting sets a minimum value. If colorIndex < current value of beatsin8(), then bright = 0. Otherwise, bright = colorIndex..
leds[k] = ColorFromPalette(currentPalette, colorIndex, thisBright, currentBlending); // Let's now add the foreground colour.
}
}
//----------------------------------------------------------------------------------------------------------------------------
// palette crossfade
void FillLEDsFromPaletteColors(uint8_t colorIndex) {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(currentPalette, colorIndex + sin8(i * 16), 255);
colorIndex += 3;
}
}
void ChangePalettePeriodically() {
uint8_t secondHand = (millis() / 1000) % 60;
static uint8_t lastSecond = 99;
if (lastSecond != secondHand) {
lastSecond = secondHand;
CRGB p = CHSV(HUE_PURPLE, 255, 255);
CRGB g = CHSV(HUE_GREEN, 255, 255);
CRGB b = CRGB::Black;
CRGB w = CRGB::White;
if (secondHand == 0) { targetPalette = RainbowColors_p; }
if (secondHand == 10) { targetPalette = CRGBPalette16(g, g, b, b, p, p, b, b, g, g, b, b, p, p, b, b); }
if (secondHand == 20) { targetPalette = CRGBPalette16(b, b, b, w, b, b, b, w, b, b, b, w, b, b, b, w); }
if (secondHand == 30) { targetPalette = LavaColors_p; }
if (secondHand == 40) { targetPalette = CloudColors_p; }
if (secondHand == 50) { targetPalette = PartyColors_p; }
}
}
//------------------------------------------------------------------------------------------------------------------------------
void one_sine_pal(uint8_t colorIndex) { // This is the heart of this program. Sure is short.
thisphase += thisspeed; // You can change direction and speed individually.
for (int k = 0; k < NUM_LEDS; k++) { // For each of the LED's in the strand, set a brightness based on a wave as follows:
int thisbright = qsuba(cubicwave8((k * allfreq) + thisphase), thiscutoff); // qsub sets a minimum value called thiscutoff. If < thiscutoff, then bright = 0. Otherwise, bright = 128 (as defined in qsub)..
leds[k] = CHSV(bgclr, 255, bgbright); // First set a background colour, but fully saturated.
leds[k] += ColorFromPalette(currentPalette, colorIndex + k, thisbright, currentBlending);
colorIndex += thisrot;
}
bgclr += bgclrinc; // You can change the background colour or remove this and leave it fixed.
}
void ChangeMe_OS() {
uint8_t secondHand = (millis() / 1000) % 60; // Increase this if you want a longer demo.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
if (lastSecond != secondHand) {
lastSecond = secondHand;
switch (secondHand) {
case 0: break;
case 5: targetPalette = RainbowColors_p; bgclr = 0; bgbright = 32; bgclrinc = 1; thisrot = 1; thisdelay = 10; thisspeed = -4; allfreq = 16; thiscutoff = 128; currentBlending = NOBLEND; break;
case 10: targetPalette = ForestColors_p; thisspeed = 12; thisrot = 0; thisspeed = 12; thisdelay = 10; thiscutoff = 128; allfreq = 64; bgclr = 50; bgbright = 15; currentBlending = LINEARBLEND; break;
case 15: SetupRandomColorPalette(); thisrot = 2; thisspeed = 16; break;
case 20: targetPalette = LavaColors_p; thisspeed = 4; break; allfreq = 16; bgclr = 50; break;
case 25: thiscutoff = 96; thisspeed = -4; thiscutoff = 224; bgclr = 20; bgbright = 8; break;
case 30: SetupRandomColorPalette(); thiscutoff = 96; thisrot = 1; break;
case 35: targetPalette = OceanColors_p; break;
case 40: SetupSimilarColorPalette(); thiscutoff = 128; break;
case 45: SetupSimilarColorPalette(); thisspeed = 3; break;
case 50: targetPalette = PartyColors_p; break;
case 55: break;
case 60: break;
}
}
}
void SetupRandomColorPalette() {
targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 192, random8(128, 255)), CHSV(random8(), 255, random8(128, 255)));
}
void SetupSimilarColorPalette() {
static uint8_t baseC = random8(); // You can use this as a baseline colour if you want similar hues in the next line, i.e. baseC+random8(0,5) for the hue.
targetPalette = CRGBPalette16(CHSV(baseC + random8(0, 10), 255, random8(128, 255)), CHSV(baseC + random8(0, 10), 255, random8(128, 255)), CHSV(baseC + random8(0, 10), 192, random8(128, 255)), CHSV(baseC + random8(0, 10), 255, random8(128, 255)));
}
//----------------------------------------------------------------------------------------------------------------------------
void matrix() { // One line matrix
if (huerot) palIndex++;
if (random8(90) > 80) {
if (thisdir == 0)
leds[0] = ColorFromPalette(currentPalette, palIndex, thisbright, currentBlending);
else
leds[NUM_LEDS - 1] = ColorFromPalette(currentPalette, palIndex, thisbright, currentBlending);
}
else {
if (thisdir == 0)
leds[0] = CHSV(bgclr, thissat, bgbri);
else
leds[NUM_LEDS - 1] = CHSV(bgclr, thissat, bgbri);
}
if (thisdir == 0) {
for (int i = NUM_LEDS - 1; i > 0; i--) leds[i] = leds[i - 1];
}
else {
for (int i = 0; i < NUM_LEDS - 1; i++) leds[i] = leds[i + 1];
}
}
// Also RainbowColors_p, RainbowStripeColors_p, OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
void ChangeMe_MP() { // A time (rather than loop) based demo sequencer. This gives us full control over the length of each sequence.
uint8_t secondHand = (millis() / 1000) % 25; // Change '25' to a different value to change length of the loop.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
if (lastSecond != secondHand) { // Debounce to make sure we're not repeating an assignment.
lastSecond = secondHand;
switch (secondHand) {
case 0: thisdelay = 50; palIndex = 95; bgclr = 140; bgbri = 4; huerot = 0; break;
case 5: targetPalette = OceanColors_p; thisdir = 1; bgbri = 0; huerot = 1; break;
case 10: targetPalette = LavaColors_p; thisdelay = 30; palIndex = 0; bgclr = 50; bgbri = 8; huerot = 0; break;
case 15: targetPalette = ForestColors_p; thisdelay = 80; bgbri = 16; bgclr = 96; palIndex = random8(); break;
case 20: palIndex = random8(); huerot = 1; break;
case 25: break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------------
//if you want you can remove the remmed lines to enable 128×64 oled display with name of the effects !!!!………..