Lab_interaccio/2018/LLAC-RGBW-varios/FASTLED/FASTLED_RGBW_noises.ino

166 lines
5.1 KiB
Arduino
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
/* FastLED RGBW Example Sketch
*
* Example sketch using FastLED for RGBW strips (SK6812). Includes
* color wipes and rainbow pattern.
*
* Written by David Madison
* http://partsnotincluded.com
*/
#include "FastLED.h"
//#include "FastLED_RGBW.h"
// #define NUM_LEDS1 150
// #define NUM_LEDS2 150
// #define NUM_LEDS3 300 // tira virtual que no se pinta
#define DATA_PIN_1 8
#define DATA_PIN_2 3
//#define DATA_PIN_3 4 // tira virtual que no se pinta, en este pin fastled no funciona
#define NUM_STRIPS 2
#define NUM_LEDS_PER_STRIP 150
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
CRGBW leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
CRGB *ledsRGB = (CRGB *) &leds[0];
CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette;
TBlendType currentBlending; // NOBLEND or LINEARBLEND
const uint8_t brightness = 255;
void setup() {
FastLED.addLeds<SK6812, DATA_PIN_1>(ledsRGB, 0, getRGBWsize(NUM_LEDS)/2);
FastLED.addLeds<SK6812, DATA_PIN_2>(ledsRGB, getRGBWsize(NUM_LEDS)/2, getRGBWsize(NUM_LEDS)/2); // la segunda se mapea a partir de un offset! Brutal!
currentPalette = PartyColors_p;
currentBlending = LINEARBLEND;
}
void loop(){
EVERY_N_MILLISECONDS(50) { // FastLED based non-blocking delay to update/display the sequence.
plasma();
}
EVERY_N_MILLISECONDS(1000) {
Serial.println(LEDS.getFPS()); // Optional check of our fps.
}
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();
}
void colorFill(CRGB c){
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = c;
//splitStrip(); // realmente hace falta generar todo en una tira entera y partirla?
FastLED.show();
delay(2);
}
delay(500);
}
void fillWhite(){
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGBW(0, 0, 0, 255);
//splitStrip();
FastLED.show();
delay(2);
}
delay(500);
}
void rainbow(){
static uint8_t hue;
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = CHSV((i * 256 / NUM_LEDS) + hue, 255, 255);
}
//splitStrip();
FastLED.show();
hue++;
}
void rainbowLoop(){
long millisIn = millis();
long loopTime = 5000; // 5 seconds
while(millis() < millisIn + loopTime){
rainbow();
delay(1);
}
}
void noise16_2()
{ // just moving along one axis = "lavalamp effect"
uint8_t scale = 1000; // the "zoom factor" for the noise
for (uint16_t i = 0; i < NUM_LEDS; i++) {
uint16_t shift_x = millis() / 10; // x as a function of time
uint16_t shift_y = 0;
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 = 4223;
uint8_t noise = inoise16(real_x, real_y, real_z) >> 8; // 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.
}
} // noise16_2()
void noise16_1() { // moves a noise up and down while slowly shifting to the side
uint16_t scale = 1000; // the "zoom factor" for the noise
for (uint16_t i = 0; i < NUM_LEDS; i++) {
uint16_t shift_x = beatsin8(5); // the x position of the noise field swings @ 17 bpm
uint16_t shift_y = millis() / 100; // the y position becomes slowly incremented
uint16_t real_x = (i + shift_x)*scale; // the x position of the noise field swings @ 17 bpm
uint16_t real_y = (i + shift_y)*scale; // the y position becomes slowly incremented
uint32_t real_z = millis() * 20; // the z position becomes quickly incremented
uint8_t noise = inoise16(real_x, real_y, real_z) >> 8; // 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.
}
} // noise16_1()