// https://wokwi.com/projects/401411534577377281
bool debug = true;
#include "FastLED.h"
#define NUM_LEDS 50
#define LED_DT 12 //data pin 9
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
int potPin = A0;
int potVal = 255;
int potColor = 255;
int potBright = 255;
int potDelay = 255;
uint8_t max_bright = 255; //half bright set
CRGB leds[NUM_LEDS];
// Add this global variable to track the breathing effect
float huePhase = 0.0;
bool ButtonTriggered = false;
#define Button 3
unsigned long previousMillis = 0; // will store last time Button was pushed
unsigned long currentMillis = 0;
const long interval = 500; // delay before another input (milliseconds)
int selectedEffect = 2;
void setup() {
if (debug) { Serial.begin(115200); }
attachInterrupt(digitalPinToInterrupt(Button), buttonPressed, CHANGE);
pinMode(Button, INPUT_PULLUP); // internal pull-up resistor
pinMode(potPin, INPUT);
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(max_bright);
}
void loop() {
if (ButtonTriggered == true) {
delay(250);
ButtonTriggered = false;
selectedEffect++;
if (selectedEffect > 2) {
selectedEffect = 0;
}
if (debug) { Serial.println("Trigger is over, back to normal"); }
}
switch (selectedEffect) {
case 0:
{
if (debug) { Serial.println("selectedEffect 0 Brightness"); }
// Breathing effect: smoothly transition hue
potVal = analogRead(potPin);
potBright = map(potVal, 0, 1023, 10, 255);
break;
}
case 1:
{
if (debug) { Serial.println("selectedEffect 1 Color"); }
potVal = analogRead(potPin);
potColor = map(potVal, 0, 1023, 0, 255);
break;
}
case 2:
if (debug) { Serial.println("selectedEffect 2 Delay"); }
potVal = analogRead(potPin);
potDelay = map(potVal, 0, 1023, 0, 255);
break;
}
//FastLED.setBrightness(potBright);
fill_solid(leds, NUM_LEDS, CHSV(potColor, 255, potBright));
FastLED.show();
delay(potDelay);
if (debug) { Serial.println(selectedEffect); }
if (debug) { Serial.println(potBright); }
if (debug) { Serial.println(potColor); }
if (debug) { Serial.println(potDelay); }
}
void buttonPressed() {
if (debug) { Serial.println("Interrupt on pin 3 was fired"); }
if (ButtonTriggered == false) {
ButtonTriggered = true;
}
}