I am having trouble getting buttonState to work. I want it to wait for me to press the button, but it starts by itself anyways.
This is my code:
#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 300
#define MAX_BRIGHTNESS 110 //maximum brightness - useful if running off battery
#define CHIPSET WS2811
#define COLOR_ORDER RGB
struct CRGB leds[NUM_LEDS];
#define BRIGHTNESS 200
#define FRAMES_PER_SECOND 30
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
delay(3000); // sanity delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
for(int dot = 0; dot < NUM_LEDS/2; dot++) {
leds[dot] = CRGB::Blue;
FastLED.show();
delay(60);
}
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB::Black;
}
}
else {
}
if (buttonState == HIGH) {
for(int dot = 0; dot < NUM_LEDS*.75; dot++) {
leds[dot] = CRGB::Blue;
FastLED.show();
delay(60);
}
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB::Black;
}
}
else {
}
if (buttonState == HIGH) {
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB::Blue;
FastLED.show();
delay(60);
}
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB ::Black;
}
}
else {
}
}