// copied from https://wokwi.com/projects/382852321750445057
#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 50
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
//
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
//
// USING palettes is MUCH simpler in practice than in theory, so first just
// run this sketch, and watch the pretty lights as you then read through
// the code. Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
//
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
//
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
void setup() {
Serial.begin(115200);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
set_max_power_in_volts_and_milliamps(5,1500);
set_max_power_indicator_LED(13);
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}
void loop()
{
updatePaletteAnalogs();
updateLeds();
}
void updatePaletteAnalogs(void) {
static int oldH, oldS, oldV;
unsigned long last = 0;
if (millis() - last >= 1000/UPDATES_PER_SECOND) {
last = millis();
// Serial.print("u");
int H = analogRead(A0) / 4;
int S = analogRead(A1) / 4;
int V = analogRead(A2) / 4;
if (oldH != H || oldS != S || oldV != V) {
Serial.print(".");
if(H != oldH){Serial.print("H:");Serial.print(H); }
if(S != oldS){Serial.print("S:");Serial.print(S); }
if(V != oldV){Serial.print("V:");Serial.print(V); }
oldH = H;
oldS = S;
oldV = V;
// Serial.print(H);Serial.print('.');
// Serial.print(S);Serial.print('.');
// Serial.print(V);Serial.print(' ');
for ( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( H, S, V);
}
}
}
}
void updateLeds(void) {
static unsigned long last = 0;
const unsigned long interval = 400;
unsigned long now = millis();
static uint8_t startIndex = 0;
if (now - last >= interval) {
last = now;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
}
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
Hue
Sat
Val