#include <FastLED.h>
#define NUM_LEDS 20
#define BASE_HUE 180
#define DATA_PIN 2
#define IN_PIN_POTM A0
CRGB leds[NUM_LEDS];
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
// Set up potentiometer
Serial.begin(115200);
pinMode(IN_PIN_POTM, INPUT);
}
void loop() {
HSVForMe();
}
void HSVForMe() {
for(int i = 0; i < NUM_LEDS; i++)
{
uint8_t mappedIndex = map(i, 0, NUM_LEDS - 1, 0, 255);
leds[i] = CHSV(BASE_HUE, 255, triwave8(mappedIndex));
}
FastLED.show();
}
void MapPotentiometer() {
// First clear any lit LEDs
FastLED.clear();
int potVal = analogRead(IN_PIN_POTM);
int mappedLED = map(potVal, 0, 1023, 0, NUM_LEDS-1);
leds[mappedLED] = CRGB::Amethyst;
FastLED.show();
delay(100);
}
void SimpleCycle() {
for(int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Amethyst;
FastLED.show();
delay(100);
/* Instead of some logic finding the *previous* LED and set that to
black (unless this is LED[0] etc.) just set the *current* LED to black
before looping to the *next* LED */
leds[i] = CRGB::Black;
}
}