Controlling 2 WS2812b strips with a NANO and 3 buttons

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();
}
1 Like