Hello,
I'm trying to run through the FASTled library examples with the press of a momentary button. So, press a button and the rainbow example will run, press it again and another example will run. I've managed to do the same thing with the Adafruit Lib but when trying to do a similar thing with the Fastled lib, I keep getting an error and I can't figure out why.
I removed the Adafruit lib to see if there was a clash but nope, same error.
Any ideas, please.
//#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include "FastLED.h"
//#include "Button.h" // Button library. Includes press, long press, double press detection.
//#include "JC_Button.h" //this worked prior
//from toher code
#define BUTTON_PIN 0
//#define PIN 2
//#define NUMPIXELS 8
#define PIN 2 //DATA_PIN
//#define CLK_PIN 11
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUMPIXELS 8 //NUM_LEDS
CRGB leds[NUMPIXELS]; //NUM_LEDS
boolean oldState = HIGH;
int mode = 0; // Currently-active animation mode, 0-9
#define FRAMES_PER_SECOND 120
uint8_t max_bright = 64;
void setup() {
Serial.begin(57600);
delay(3000); // 3 second delay for recovery
pinMode(BUTTON_PIN, INPUT_PULLUP);
FastLED.addLeds<LED_TYPE,PIN,COLOR_ORDER>(leds, NUMPIXELS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set master brightness control
FastLED.setBrightness(max_bright);
}
// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, juggle, bpm }; //deleted sinelon
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
void loop()
{
// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND);
// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
// EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
// readbutton(); // Button press increases the ledMode up to last contiguous mode and then starts over at 0.
// Get current button state.
boolean newState = digitalRead(BUTTON_PIN);
// Check if state changed from high to low (button press).
if((newState == LOW) && (oldState == HIGH)) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if(newState == LOW) { // Yes, still low
if(++mode > 5) mode = 0; // Advance to next mode, wrap around after #8
switch(mode) { // Start the new animation...
case 0:
rainbow(50); // Black/off
break;
case 1:
rainbowWithGlitter(50); // Red
break;
case 2:
addGlitter(50); // Green
break;
case 3:
confetti(50); // Blue
break;
case 4:
bpm(50); // White
break;
case 5:
juggle(50); // Purple
break;
}
}
}
// Set the last-read button state to the old state.
oldState = newState;
}
}
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
//void nextPattern()
//{
// add one to the current pattern number, and wrap around at the end
// gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
//}
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUMPIXELS, gHue, 7);
}
void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}
void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUMPIXELS) ] += CRGB::White;
}
}
void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUMPIXELS, 10);
int pos = random16(NUMPIXELS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}
//void sinelon()
//{
// a colored dot sweeping back and forth, with fading trails
// fadeToBlackBy( leds, NUM_LEDS, 20);
// int pos = beatsin16(13,0,NUM_LEDS);
// leds[pos] += CHSV( gHue, 255, 192);
//}
void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for( int i = 0; i < NUMPIXELS; i++) { //9948
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
}
}
void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUMPIXELS, 20);
byte dothue = 0;
for( int i = 0; i < 8; i++) {
leds[beatsin16(i+7,0,NUMPIXELS-1)] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
//void readbutton() { // Read the button and increase the mode
// myBtn.read();
// if(myBtn.wasReleased()) {
// nextPattern();
// }
//} // readbutton()
I'll post the error next, as there is no room