Hey. Never posted before anything here before.
I have been messing around with FastLED and I am trying to make it so if you have a button a certain pattern is performed. If you press another button, then a different pattern is performed. ETC. I can get it to work with one button. But when I add the second button, nothing will work at all. Just the first few lights will strobe out uncontrollably. Any insight helps. Code is pasted below. As I said it works until I add the second button.
#include <FastLED.h>
#define NUM_LEDS 25
#define LED_PIN 6
CRGB leds[NUM_LEDS];
int buttonpress1 = 0;
int pattern1 = 0;
int buttonpress2 = 0;
int pattern2 = 0;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN,GRB>(leds,NUM_LEDS);
FastLED.setBrightness(25);
pinMode(2,INPUT);
}
void loop() {
buttonpress1 = digitalRead(2);
buttonpress2 = digitalRead(4);
if (buttonpress1 == HIGH){
pattern1 = 1;
}
if(pattern1 == 1){
EVERY_N_MILLISECONDS(111) {
//Creating a new pixel for led [0] (the first LED)
//CHSV STRUCTURE
// leds[i] = CHSV(Hue --> `colour`,saturation, value)
leds[0] = CHSV(40, random8(), random8(100,225));
//Copy each pixel to the next one, starting at last LED
//This way the leds are "moving" along the entire strip
for (int i = NUM_LEDS - 1; i>0; i--){
leds[i] = leds[i - 1];
}
FastLED.show();
}
}
if (buttonpress1 == LOW){
pattern1 = 0;
}
if(pattern1 ==0){
FastLED.clear(true);}
if (buttonpress2 == HIGH){
pattern2 = 1;
}
if(pattern2 == 1){
EVERY_N_MILLISECONDS(100) {
//Creating a new pixel for led [0] (the first LED)
//CHSV STRUCTURE
// leds[i] = CHSV(Hue --> `colour`,saturation, value)
leds[0] = CHSV(90, random8(), random8(100,225));
//Copy each pixel to the next one, starting at last LED
//This way the leds are "moving" along the entire strip
for (int x = NUM_LEDS - 1; x>0; x--){
leds[x] = leds[x - 1];
}
FastLED.show();
}
}
if (buttonpress2 == LOW){
pattern2 = 0;
}
if(pattern2 ==0){
FastLED.clear(true);}
}