#include "FastLED.h"
#define BUTTON_PIN 3
#define NUM_LEDS 30
#define DATA_PIN 7
volatile bool action = false;
int intensityPin = A0;
int speedPin = A2;
int speed;
int intensity;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, DATA_PIN>(leds, NUM_LEDS);
pinMode(speedPin, INPUT);
pinMode(intensityPin, INPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
if (action) {
// allLED();
action = false;
} else {
allLED();
}
}
void buttonPressed() {
action = true;
}
void allLED() {
red_led();
green_led();
blue_led();
}
void red_led() {
if (digitalRead(BUTTON_PIN) == LOW)
for (int i = 0; i <= NUM_LEDS; i++) {
leds[i] = CRGB(0,intensity,0);
intensity = map(analogRead(intensityPin),0,1023,0,255);
delay(speed);
speed = map(analogRead(speedPin),0,1023,255,0);
FastLED.show();
FastLED.clear();
}
}
void green_led() {
if (digitalRead(BUTTON_PIN) == LOW)
for (int i = 0; i <= NUM_LEDS; i++) {
leds[i] = CRGB(intensity,0,0);
intensity = map(analogRead(intensityPin),0,1023,0,255);
delay(speed);
speed = map(analogRead(speedPin),0,1023,255,0);
FastLED.show();
FastLED.clear();
}
}
void blue_led() {
if (digitalRead(BUTTON_PIN) == LOW)
for (int i = 0; i <= NUM_LEDS; i++) {
leds[i] = CRGB(0,0,intensity);
intensity = map(analogRead(intensityPin),0,1023,0,255);
delay(speed);
speed = map(analogRead(speedPin),0,1023,255,0);
FastLED.show();
FastLED.clear();
}
}