I tried a generic code from a youtube video to test if my button input was working and it did work, so it is wired correctly.
Basically I want to use the push button as a mode selector by making each press add 1 to the counter.
I can run the code but when pressing the button it does not pick it up like it did in the test code provided for me
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 21
int counter = 0;
const int buttonPin = 4;
int buttonState = 0;
int delayTime;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2813, LED_PIN, GRB>(leds, NUM_LEDS);
pinMode(buttonPin, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop(){
Serial.print(counter);
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
counter + 1;
//Reset count if over max mode number
if(counter == 4)
{
counter = 1;
}
}
//Change mode
if(counter == 1) //red and blue
{
for (int i = 0; i <= 20; i++) {
leds[i] = CRGB ( 0, 0, 200);
FastLED.show();
delay(40);
}
for (int i = 20; i >= 0; i--) {
leds[i] = CRGB ( 200, 0, 0);
FastLED.show();
delay(40);
}
}
else if(counter == 2) //yellow and green
{
for (int i = 0; i <= 20; i++) {
leds[i] = CRGB ( 200, 200, 0);
FastLED.show();
delay(40);
}
for (int i = 20; i >= 0; i--) {
leds[i] = CRGB ( 0, 200, 0);
FastLED.show();
delay(40);
}
}
else if(counter == 3) //white and pink
{
for (int i = 0; i <= 20; i++) {
leds[i] = CRGB ( 100, 100, 100);
FastLED.show();
delay(40);
}
for (int i = 20; i >= 0; i--) {
leds[i] = CRGB ( 100, 0, 100);
FastLED.show();
delay(40);
}
}
}