Controlling 2 WS2812b strips with a NANO and 3 buttons

Just finished a prototype for a Turn Sequence Counter for Arkham Horror LCG by Fantasy Flight and I have completed the soldering and wiring to take this project to the WS2812b level instead of boring LED's. Need some help with the Coding. Not sure how to get buttons to turn on the 2812 led's one at a time and they stay on until another button is pressed. I have 3 buttons wired in and need them to control 2 strands of ws2812b rbg's. I have attached a pic of the wiring and both 4 light strips have been tested.

I have some code that worked led's but now I need to convert it to work with the RGB's. Coding is not my strong suit so any help will be much appreciated. Here is my code so far.

#include <Adafruit_NeoPixel.h>
#define PIN1 5
#define PIN2 3
#define NUM_LEDS 3
#define NUM_LEDS2 3
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LEDS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS2, PIN2, NEO_GRB + NEO_KHZ800);
class PushButton
{
  public:
    PushButton(uint8_t pin) // Constructor (executes when a PushButton object is created)
      : pin(pin) { // remember the push button pin
      pinMode(pin, INPUT_PULLUP); // enable the internal pull-up resistor
    };
    bool isPressed() // read the button state check if the button has been pressed, debounce the button as well
    {
      bool pressed = false;
      bool state = digitalRead(pin);               // read the button's state
      int8_t stateChange = state - previousState;  // calculate the state change since last time

      if (stateChange == falling) { // If the button is pressed (went from high to low)
        if (millis() - previousBounceTime > debounceTime) { // check if the time since the last bounce is higher than the threshold
          pressed = true; // the button is pressed
        }
      }
      if (stateChange == rising) { // if the button is released or bounces
        previousBounceTime = millis(); // remember when this happened
      }

      previousState = state; // remember the current state
      return pressed; // return true if the button was pressed and didn't bounce
    };
  private:
    uint8_t pin;
    bool previousState = HIGH;
    unsigned long previousBounceTime = 0;

    const static unsigned long debounceTime = 25;
    const static int8_t rising = HIGH - LOW;
    const static int8_t falling = LOW - HIGH;
};
// this is for led's looks like ill need to change this for RGB's
const uint8_t ledPins[] = {5, 3};
const uint8_t nb_leds = sizeof(ledPins) / sizeof(ledPins[0]);
PushButton pushbutton = {6};

class PushButton2
{
  public:
    PushButton2(uint8_t pin2) // Constructor (executes when a PushButton object is created)
      : pin2(pin2) { // remember the push button pin
      pinMode(pin2, INPUT_PULLUP); // enable the internal pull-up resistor
    };
    bool isPressed() // read the button state check if the button has been pressed, debounce the button as well
    {
      bool pressed = false;
      bool state2 = digitalRead(pin2);               // read the button's state
      int8_t stateChange2 = state2 - previousState2;  // calculate the state change since last time

      if (stateChange2 == falling) { // If the button is pressed (went from high to low)
        if (millis() - previousBounceTime2 > debounceTime2) { // check if the time since the last bounce is higher than the threshold
          pressed = true; // the button is pressed
        }
      }
      if (stateChange2 == rising) { // if the button is released or bounces
        previousBounceTime2 = millis(); // remember when this happened
      }

      previousState2 = state2; // remember the current state
      return pressed; // return true if the button was pressed and didn't bounce
    };
  private:
    uint8_t pin2;
    bool previousState2 = HIGH;
    unsigned long previousBounceTime2 = 0;

    const static unsigned long debounceTime2 = 25;
    const static int8_t rising = HIGH - LOW;
    const static int8_t falling = LOW - HIGH;
};


PushButton2 pushbutton2 = {7};

class PushButton3
{
  public:
    PushButton3(uint8_t pin3) // Constructor (executes when a PushButton object is created)
      : pin3(pin3) { // remember the push button pin
      pinMode(pin3, INPUT_PULLUP); // enable the internal pull-up resistor
    };
    bool isPressed() // read the button state check if the button has been pressed, debounce the button as well
    {
      bool pressed = false;
      bool state3 = digitalRead(pin3);               // read the button's state
      int8_t stateChange3 = state3 - previousState3;  // calculate the state change since last time

      if (stateChange3 == falling) { // If the button is pressed (went from high to low)
        if (millis() - previousBounceTime3 > debounceTime3) { // check if the time since the last bounce is higher than the threshold
          pressed = true; // the button is pressed
        }
      }
      if (stateChange3 == rising) { // if the button is released or bounces
        previousBounceTime3 = millis(); // remember when this happened
      }

      previousState3 = state3; // remember the current state
      return pressed; // return true if the button was pressed and didn't bounce
    };
  private:
    uint8_t pin3;
    bool previousState3 = HIGH;
    unsigned long previousBounceTime3 = 0;

    const static unsigned long debounceTime3 = 25;
    const static int8_t rising = HIGH - LOW;
    const static int8_t falling = LOW - HIGH;
};


PushButton3 pushbutton3 = {9};


void setup() {
  strip1.begin();
  strip1.show(); // Initialize all pixels to 'off'
  strip2.begin();
  strip2.show(); // Initialize all pixels to 'off'
  for (const uint8_t &ledPin : ledPins)
    pinMode(ledPin, OUTPUT);
}

void loop() {
  static uint8_t nb_presses = 0;
  if (pushbutton.isPressed()) {
    if (nb_presses == nb_leds) {
      for (const uint8_t &ledPin : ledPins)
        digitalWrite(ledPin, LOW);
      nb_presses = 0;
    } else {
      digitalWrite(ledPins[nb_presses], HIGH);
      nb_presses++;
    }
  }
  if (pushbutton2.isPressed()){
    clearRound();
  }
}

void clearRound(){
  digitalWrite (8, LOW);
  digitalWrite (5, LOW);
  digitalWrite (4, LOW);
}





void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip1.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

This project is to help keep track of the Phases of a Round and the amount of actions a player has during the investigation phase of The Arkham Horror LCG, game is amazing but can be a chore with out a tracker, I have a strictly hard wired tracker that uses SPST switches to control each led no arduino and it has made the game much more enjoyable because it forces you to follow turn sequence correctly. This RBG model will be more intuitive and better looking.

Hi moJoeRedRog
I like your project and I can help if you want. I don't know much the Adafruit_NeoPixel library, I preferably use FastLED. If this is OK for you, then I can help...

However, I'm not sure I understand everything you want to do in your project. Maybe you can explain a little more.
E.g. you say the 3 buttons must control 2 led strips. But after you talk about 4 strips. So, how many buttons (3?) and strips are there? And what are the actions of each button? Can you answer by saying for example :

  • Button n (pin x) does xxx on strip number y

By the way, I'm from France, so there may be some time shift between us if you're in the US, which may increase the time to write a correct code (I'll only be able to test if it compiles, not how it works, because I don't have the strips at home, so there may be quite a few questions and answers and testing phases on your side). So please be very precise and specific in your answers (sorry about that).

lesept:
However, I'm not sure I understand everything you want to do in your project. Maybe you can explain a little more.
E.g. you say the 3 buttons must control 2 led strips. But after you talk about 4 strips. So, how many buttons (3?) and strips are there? And what are the actions of each button? Can you answer by saying for example :

  • Button n (pin x) does xxx on strip number y

By the way, I'm from France, so there may be some time shift between us if you're in the US, which may increase the time to write a correct code (I'll only be able to test if it compiles, not how it works, because I don't have the strips at home, so there may be quite a few questions and answers and testing phases on your side). So please be very precise and specific in your answers (sorry about that).

Hey Lesept thanks for your interest in helping me out with this project, and yes I can definetely use fast led on this. I am good with that.

I am using 2 strips of 4 ws2812b led's, strip 1 keeps track of the Round sequence, by lighting up one led at a time and the current and previous leds stay lit. I want one button to advance the Round sequence. Then the second strip of led's keeps track of the action counter, it has 4 led's as well. The second button advances these leds, the third button I would like to be a master reset button that clears both strips.
so button A on pin9 lights up LED 1 on strip 1 pin5 with each press it continues Moving from led 1 to led 4.
button B on pin6 lights up LED 1 on strip2 pin3 with each press starting at 1 and advancing to 4.
button C on pin7 resets both LED strips to all off

I included a pic of the led strips.

I cut and pasted some basic code switching to Fast_led I will try to add some button control. Here is what I have so far

#include <FastLED.h>
#define NUM_LEDS 4
#define DATA_PIN 5
CRGB leds[NUM_LEDS];
#define NUM_LEDS2 4
#define DATA_PIN2 3
CRGB leds2[NUM_LEDS2];

void setup() {
  // put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
}

void loop() {
  // put your main code here, to run repeatedly:
        strip1();
        strip2();        
}

void strip1(){
        leds[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds[1] = CRGB::Green; 
        FastLED.show(); 
        delay(30);
        leds[2] = CRGB::Red; 
        FastLED.show(); 
        delay(30);
        leds[3] = CRGB::HotPink; 
        FastLED.show(); 
        delay(30);
}

void strip2(){
        leds2[0] = CRGB::Green; 
        FastLED.show(); 
        delay(30); 
        leds2[1] = CRGB::Green; 
        FastLED.show(); 
        delay(30); 
        leds2[2] = CRGB::Green; 
        FastLED.show(); 
        delay(30);
        leds2[3] = CRGB::Red; 
        FastLED.show(); 
        delay(30);  
        
}

Ok I understand more.
To be sure :

At the beginning : no lit led.

Strip 1& button 1. One clic lits led 1. One more clic lits led 2. One more clic lits led 3and off led 1. One more clic lits led 4 and offs led 2. And then what?

Strip2&button 2. Each clic offs the current led and lits the next. When at led 4 does it go back to led 1 or offs everything?

Button 3 erases all leds of both strips. This one is easy.

Last question, very important: will you ALWAYS have 4 leds on each strip (never less, never more) ? If yes, I'll do the code differently

lesept:
Ok I understand more.
To be sure :

At the beginning : no lit led.

Strip 1& button 1. One clic lits led 1. One more clic lits led 2. One more clic lits led 3and off led 1. One more clic lits led 4 and offs led 2. And then what?

Strip2&button 2. Each clic offs the current led and lits the next. When at led 4 does it go back to led 1 or offs everything?

Button 3 erases all leds of both strips. This one is easy.

almost, strip 1 is controlled by button 1, 1st press lights up led 1, second press lights up 1 & 2, third press lights up 1 & 2 & 3, the fourth press lights up 1 & 2 & 3 & 4

same goes for the 2nd strip but the strip 2 is controlled by button 2

then the third button clears both strips.

Last question, very important: will you ALWAYS have 4 leds on each strip (never less, never more) ? If yes, I'll do the code differently

And what if you accidentally press button 1 a fifth time?

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

I try'd your code but undesirable things happened. The 1st string 1st led flickers and when button 1 is pressed and held it lights up the rgb strip while holding it down starting at 1 and ending at 2nd strip 1, if you hold down the reset button it stops flickering until you let go.

I have made some real primative code that almost works perfectly. have a look. Only problem is that the turning on of the leds is glitchy. it will light more than one at a time and wont light the 4th works on both strings each controlled by its respective button, and the third button reset works.

#include <FastLED.h>
#define NUM_LEDS 4
#define DATA_PIN 5
CRGB leds[NUM_LEDS];
#define NUM_LEDS2 4
#define DATA_PIN2 3
CRGB leds2[NUM_LEDS2];
const int buttonPin = 7;
const int buttonPin2 = 6;
const int buttonPin3 = 9;
int buttonState = 0;
int buttonState1 = 0;
int buttonState2 = 0;

class PushButton
{
  public:
    PushButton(uint8_t pin) // Constructor (executes when a PushButton object is created)
      : pin(pin) { // remember the push button pin
      pinMode(pin, INPUT_PULLUP); // enable the internal pull-up resistor
    };
    bool isPressed() // read the button state check if the button has been pressed, debounce the button as well
    {
      bool pressed = false;
      bool state = digitalRead(pin);               // read the button's state
      int8_t stateChange = state - previousState;  // calculate the state change since last time

      if (stateChange == falling) { // If the button is pressed (went from high to low)
        if (millis() - previousBounceTime > debounceTime) { // check if the time since the last bounce is higher than the threshold
          pressed = true; // the button is pressed
        }
      }
      if (stateChange == rising) { // if the button is released or bounces
        previousBounceTime = millis(); // remember when this happened
      }

      previousState = state; // remember the current state
      return pressed; // return true if the button was pressed and didn't bounce
    };
  private:
    uint8_t pin;
    bool previousState = HIGH;
    unsigned long previousBounceTime = 0;

    const static unsigned long debounceTime = 25;
    const static int8_t rising = HIGH - LOW;
    const static int8_t falling = LOW - HIGH;
};

PushButton pushbutton = {7};

class PushButton2
{
  public:
    PushButton2(uint8_t pin2) // Constructor (executes when a PushButton object is created)
      : pin2(pin2) { // remember the push button pin
      pinMode(pin2, INPUT_PULLUP); // enable the internal pull-up resistor
    };
    bool isPressed() // read the button state check if the button has been pressed, debounce the button as well
    {
      bool pressed = false;
      bool state2 = digitalRead(pin2);               // read the button's state
      int8_t stateChange2 = state2 - previousState2;  // calculate the state change since last time

      if (stateChange2 == falling) { // If the button is pressed (went from high to low)
        if (millis() - previousBounceTime2 > debounceTime2) { // check if the time since the last bounce is higher than the threshold
          pressed = true; // the button is pressed
        }
      }
      if (stateChange2 == rising) { // if the button is released or bounces
        previousBounceTime2 = millis(); // remember when this happened
      }

      previousState2 = state2; // remember the current state
      return pressed; // return true if the button was pressed and didn't bounce
    };
  private:
    uint8_t pin2;
    bool previousState2 = HIGH;
    unsigned long previousBounceTime2 = 0;

    const static unsigned long debounceTime2 = 25;
    const static int8_t rising = HIGH - LOW;
    const static int8_t falling = LOW - HIGH;
};


PushButton2 pushbutton2 = {6};

class PushButton3
{
  public:
    PushButton3(uint8_t pin3) // Constructor (executes when a PushButton object is created)
      : pin3(pin3) { // remember the push button pin
      pinMode(pin3, INPUT_PULLUP); // enable the internal pull-up resistor
    };
    bool isPressed() // read the button state check if the button has been pressed, debounce the button as well
    {
      bool pressed = false;
      bool state3 = digitalRead(pin3);               // read the button's state
      int8_t stateChange3 = state3 - previousState3;  // calculate the state change since last time

      if (stateChange3 == falling) { // If the button is pressed (went from high to low)
        if (millis() - previousBounceTime3 > debounceTime3) { // check if the time since the last bounce is higher than the threshold
          pressed = true; // the button is pressed
        }
      }
      if (stateChange3 == rising) { // if the button is released or bounces
        previousBounceTime3 = millis(); // remember when this happened
      }

      previousState3 = state3; // remember the current state
      return pressed; // return true if the button was pressed and didn't bounce
    };
  private:
    uint8_t pin3;
    bool previousState3 = HIGH;
    unsigned long previousBounceTime3 = 0;

    const static unsigned long debounceTime3 = 25;
    const static int8_t rising = HIGH - LOW;
    const static int8_t falling = LOW - HIGH;
};


PushButton3 pushbutton3 = {9};


void setup() {
  // put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
FastLED.clear();
FastLED.show();
}




void loop() {
  // put your main code here, to run repeatedly:
        buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (pushbutton.isPressed()) {
    // turn LED on:
   press1();
  }  else if 
    (pushbutton.isPressed()){
      press2();
      delay(150);
  }  else if
    (pushbutton.isPressed()){
      press3();
      delay(150);
    }  else if 
    (pushbutton.isPressed()){
      press4();
      delay(150);
    }
   else if (pushbutton2.isPressed()){
    string2press1();
    delay(150);
   }
    else if (pushbutton2.isPressed()){
      string2press2();
      delay(150);
    }
     else if (pushbutton2.isPressed()){
        string2press3();
        delay(150);
      }
       else if (pushbutton2.isPressed()){
          string2press4();
        }
   else if (pushbutton3.isPressed()){
    resetStrings();
   }
}




void press1(){
        leds[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}

void press2(){
        leds[1] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}

void press3(){
        leds[2] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds[1] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}

void press4(){
        leds[3] = CRGB::Blue;
        FastLED.show();
        delay(3);
        leds[2] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds[1] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}



void string2press1(){
        leds2[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}

void string2press2(){
        leds2[1] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds2[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}

void string2press3(){
        leds2[2] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds2[1] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds2[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}

void string2press4(){
        leds2[3] = CRGB::Blue;
        FastLED.show();
        delay(3);
        leds2[2] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds2[1] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds2[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}


void resetStrings(){
 FastLED.clear();
 FastLED.show();
}

I know it aint pretty but i think it can be made to work. Is there a better way to activate my functions one button press at a time. maybe ? Could maybe a switch Case be used to activate the led on functions.

Why are you using classes for something that is so obviously not suited to classes?

You are making the code ten times more complicated than it needs to be.
Also

PushButton3 pushbutton3 = {9};

Wrong sort of brackets.

This code is just silly

void press2(){
        leds[1] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
        leds[0] = CRGB::Blue; 
        FastLED.show(); 
        delay(30);
}

What is wrong with :-

void press2(){
        leds[1] = CRGB::Blue; 
        leds[0] = CRGB::Blue; 
        FastLED.show(); 
}

could we remove the classes and keep the functions. My code was just the best i could do with the samples of code I got, as long as it works I can do it the way you think is best. I like the functions though as they allow me to change the color real easy and keep my loop simpler. Do you agree. I did not write that classes code it was a old sketch given to me to get my previous regular led model to work, so i tried to use it with the ws2812b model. I almost got it to work.

lesept:
How about this ?

#include <FastLED.h>

/*
  No copyright, use it at your own risks :wink:
*/
// 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.

This is what I mean :

moJoeRedRog:
however if you press again strip 2 light 1 comes on.

What do you mean ?

For button2, try

  if (!StateB1) ChangeStrip1 ();
 else if (!StateB2) ChangeStrip2 ();
 else if (!StateBReset) ResetStrips ();

Not sure it will change anything though...

Button 2 does nothing

That's weird, there is sth wrong in the checkbutton function.

I wrote the code as it they were pushbuttons; they act when you push and release them. What button do you use, this kind?

however if you press again strip 2 light 1 comes on.

Got it : please change :
  NumStrip1 = min(NumStrip1+1,NUM_LEDS);to  NumStrip1 = min(NumStrip1+1,NUM_LEDS-1);and the same in the other function.

Good Morning

I am using those exact buttons.

I have implemented your changes and strip one is now working perfectly. How ever button 2 does nothing, I tried changing the button and I ran some code and the button works and so does the strip but with your sketch it does not. the reset button works perfectly as well.

I am using 10k ohm resistors on the button grounds, i tried it with out the resistor and the results were the same.

I also tried changing button 2 to pin 11 on the arduino but still no effect so I put it back on pin 6

Bonjour

I have changed the color of strip 2 after much code review and it now works:) dont know why red wouldn't work but green does however it lights up more like yellow. The color red wont work on the other strip either, kind of strange. but hey we have achieved success, Thank you for helping me out on this one, Merci !

there is a error message with the color red in place.

warning: overflow in implicit constant conversion [-Woverflow]
int ledColor2 = CRGB::Red; // Color for strip 2

Sorry : my mistake. Change the line

bool StateB2 = digitalRead(PIN_BUTTON1);

to
bool StateB2 = digitalRead(PIN_BUTTON2);(PIN_BUTTON2 instead of PIN_BUTTON1).
It should be OK now (fingers crossed)

Sorry : my mistake. Forget my previous message.

You can always delete the post. Use the modify drop down menu under your post.

Grumpy_Mike:
You can always delete the post. Use the modify drop down menu under your post.

Thanks, done.

lesept:
Sorry : my mistake. Change the line

bool StateB2 = digitalRead(PIN_BUTTON1);

to
bool StateB2 = digitalRead(PIN_BUTTON2);(PIN_BUTTON2 instead of PIN_BUTTON1).
It should be OK now (fingers crossed)

It all works perfect. Thanks again. Got a quick question though would it be hard to modify this code to allow me to set the individual led's to different colors?

No, not very hard, tell me the colors for each led and each strip.
There is a color reference here : Pixel reference · FastLED/FastLED Wiki · GitHub

In this version of the code, the button handling is minimal. This means that you're supposed to push and release quickly, never keep the button pushed. Is it ok for you or would you need some better button handling, such as waiting for the button to be released to increment the leds?