#include "FastLED.h"
#define NUM_LEDS 40
CRGB leds[NUM_LEDS];
#define LEFTPIN 2
#define RIGHTPIN 3
#define EYEPIN 6
const int buttonPin = 8;
int lastButtonState = LOW;
void setup()
{
FastLED.addLeds<WS2811, LEFTPIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2811, RIGHTPIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2811, EYEPIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
pinMode(buttonPin, INPUT);
}
// *** REPLACE FROM HERE ***
void loop() {
int currentButtonState = digitalRead(buttonPin);
// Check if the button has transitioned from not being pressed to being pressed.
if (currentButtonState == HIGH && lastButtonState == LOW) {
// Button was pressed, execute Sparkle.
Sparkle(0xff, 0x00, 0x00, 0);
Sparkle(0xff, 0xff, 0xff, 0);
// Add a small delay to debounce the button press.
// This helps in avoiding detecting a single press multiple times.
delay(50); // Delay for 50 milliseconds. Adjust this value as necessary.
}
// Update the lastButtonState with the current state for the next iteration.
lastButtonState = currentButtonState;
}
void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
int Pixel = random(NUM_LEDS);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
setPixel(Pixel,0,0,0);
}
// *** REPLACE TO HERE ***
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}