lesept:
How about this ?#include <FastLED.h>
/*
No copyright, use it at your own risks ![]()
*/
// Define the arrays of leds
#define PIN_STRIP1 5
#define PIN_STRIP2 3
#define COLOR_ORDER GRB
#define LED_TYPE WS2812
#define NUM_LEDS 4
uint8_t max_bright = 255;
struct CRGB leds1[NUM_LEDS];
struct CRGB leds2[NUM_LEDS];
int ledColor1 = CRGB::Blue; // Color for strip 1
int ledColor2 = CRGB::Red; // Color for strip 2
// Define buttons
#define PIN_BUTTON1 9
#define PIN_BUTTON2 6
#define PIN_BUTTON_RESET 7
// Global vars
byte NumStrip1 = 0;
byte NumStrip2 = 0;
void setup() {
LEDS.addLeds<LED_TYPE, PIN_STRIP1, COLOR_ORDER>(leds1, NUM_LEDS);
LEDS.addLeds<LED_TYPE, PIN_STRIP2, COLOR_ORDER>(leds2, NUM_LEDS);
FastLED.setBrightness(max_bright);
FastLED.clear();
FastLED.show();
// Connect buttons like this :
// GND -- Button -- Pin
pinMode(PIN_BUTTON1, INPUT_PULLUP); // Button 1
pinMode(PIN_BUTTON2, INPUT_PULLUP); // Button 2
pinMode(PIN_BUTTON_RESET, INPUT_PULLUP); // Reset button
}
void loop() {
Checkbuttons();
}
void Checkbuttons()
{
bool StateB1 = digitalRead(PIN_BUTTON1);
delay(50);
bool StateB2 = digitalRead(PIN_BUTTON1);
delay(50);
bool StateBReset = digitalRead(PIN_BUTTON_RESET);
delay(50);
if (!StateB1) ChangeStrip1 ();
if (!StateB2) ChangeStrip2 ();
if (!StateBReset) ResetStrips ();
}
void ChangeStrip1 () {
leds1[NumStrip1] = ledColor1;
NumStrip1 = min(NumStrip1+1,NUM_LEDS);
FastLED.show();
}
void ChangeStrip2 () {
leds2[NumStrip2] = ledColor2;
NumStrip2 = min(NumStrip2+1,NUM_LEDS);
FastLED.show();
}
void ResetStrips () {
FastLED.clear();
NumStrip1 = 0;
NumStrip2 = 0;
FastLED.show();
}
I think my buttons are wired differently, what exactly do you mean when you say wire buttons like this
gnd -- button -- pin
not sure what that looks like
ok I got it I put the buttons as you said and almost success, button 1 lights up the first strip 1 at a time however if you press again strip 2 light 1 comes on. Button 2 does nothing and button 3 resets just fine.