Hello I'm trying to control two separate LED strips from one Arduino, each strip has it's own button and set of patterns to cycle through.
I follow the Scott Marley FastLED tutorial (specifically, FastLED Basics Episode 5 - Multiple patterns using a timer or button), so I understand how to get the patterns to run when they are uploaded individually. My idea was to add a "_0" and "_1" version of all the variables that needed them and add my two separate patterns.
It seems to get hung up on:
error: 'nextPattern_1' was not declared in this scope
btn_1.attachClick(nextPattern_1);
I can seem to find anything wrong with format at that point.
Am I thinking about this wrong?
Thanks in advance!
#include <FastLED.h>
#include <OneButton.h>
#define NUM_LEDS_PER_STRIP 18
#define BTN_PIN_0 3
#define BTN_PIN_1 5
#define LED_PIN_0 2
#define LED_PIN_1 4
CRGB leds[NUM_LEDS_PER_STRIP];
uint8_t patternCounter_0 = 0;
uint8_t patternCounter_1 = 0;
OneButton btn_0(BTN_PIN_0, true, true);
OneButton btn_1(BTN_PIN_1, true, true);
void setup() {
FastLED.addLeds<WS2812B, LED_PIN_0, GRB>(leds, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, LED_PIN_1, GRB>(leds, NUM_LEDS_PER_STRIP);
Serial.begin(57600);
btn_0.attachClick(nextPattern_0);
btn_1.attachClick(nextPattern_1);
}
void loop_0() {
switch (patternCounter_0) {
case 0:
movingDots();
break;
case 1:
rainbowBeat();
break;
case 2:
redWhiteBlue();
break;
}
FastLED.show();
btn_0.tick();
}
void loop_1() {
switch (patternCounter_1) {
case 0:
brightness_lv1();
break;
case 1:
brightness_lv2();
break;
case 2:
brightness_lv3();
break;
}
FastLED.show();
btn_1.tick();
}
void nextPattern_0() {
patternCounter_0 = (patternCounter_0 + 1) % 3; // Change the number after the % to the number of patterns you have
void nextPattern_1() {
patternCounter_1 = (patternCounter_1 + 1) % 3; // Change the number after the % to the number of patterns you have
}
//------- Put your patterns below -------//
///---Underglow---///
void movingDots() {
uint16_t posBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 32767);
uint16_t posBeat4 = beatsin16(60, 0, NUM_LEDS - 1, 0, 32767);
// Wave for LED color
uint8_t colBeat = beatsin8(45, 0, 255, 0, 0);
leds[(posBeat + posBeat2) / 2] = CHSV(colBeat, 255, 255);
leds[(posBeat3 + posBeat4) / 2] = CHSV(colBeat, 255, 255);
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.setBrightness(50);
}
void rainbowBeat() {
uint16_t beatA = beatsin16(30, 0, 255);
uint16_t beatB = beatsin16(20, 0, 255);
fill_rainbow(leds, NUM_LEDS, (beatA+beatB)/2, 8);
FastLED.setBrightness(50);
}
void redWhiteBlue() {
uint16_t sinBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(30, 0, NUM_LEDS - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 43690);
leds[sinBeat] = CRGB::Blue;
leds[sinBeat2] = CRGB::Red;
leds[sinBeat3] = CRGB::White;
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.setBrightness(50);
}
///---Merch Light---///
void brightness_lv1() {
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
FastLED.setBrightness(50);
}
void brightness_lv2() {
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
FastLED.setBrightness(25);
}
void brightness_lv3() {
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
FastLED.setBrightness(0);
}