slurry bowl
Active member
Greetings forum dwellers.
I have been enjoying FastLED for awhile but always have challenges incorporating a button w/Teensy.
Some of the other button libraries for Arduino benefit from default pull-up resistors on that board and when applied
to Teensy, they dont work, at least that is what I think has been my problem. Cree (another forum member) did post some code that worked w/ Teensy and a button.
So......
I want to cycle through a list of patterns when the button is pushed, simple button cycler sorta thing.
Except I have 2 data pins on my Teensy LC, 10 and 17. So when the button is pushed it changes the data on both strips.
Here is my code w/o the button and it works great.
Here is my attempt at incorporating a button. Unfortunately its not working. I am trying to declare my functions below the void loop.
any help most appreciated.
I have been enjoying FastLED for awhile but always have challenges incorporating a button w/Teensy.
Some of the other button libraries for Arduino benefit from default pull-up resistors on that board and when applied
to Teensy, they dont work, at least that is what I think has been my problem. Cree (another forum member) did post some code that worked w/ Teensy and a button.
So......
I want to cycle through a list of patterns when the button is pushed, simple button cycler sorta thing.
Except I have 2 data pins on my Teensy LC, 10 and 17. So when the button is pushed it changes the data on both strips.
Here is my code w/o the button and it works great.
Code:
#include <FastLED.h>
#define BUTTON_PIN 3
#define NUM_LEDS_core 60
#define NUM_LEDS_arm 54
CRGB coreLeds[NUM_LEDS_core];
CRGB armLeds[NUM_LEDS_arm];
CRGBPalette16 gPal;
void setup() {
FastLED.addLeds<NEOPIXEL, 10>(coreLeds, NUM_LEDS_core);
FastLED.addLeds<NEOPIXEL, 17>(armLeds, NUM_LEDS_arm);
}
void loop() {
//CORE
for(int led = 0; led < NUM_LEDS_core; led++) {
coreLeds[led] = CRGB::Green;
}
FastLED.show();
//ARMS
fadeToBlackBy( armLeds, NUM_LEDS_arm, 8);
byte dothue = 10;
for( int i = 0; i < 8; i++) {
armLeds[beatsin16( i+0, 0, NUM_LEDS_arm )] |= CHSV(dothue, 250, 80);
dothue += 22;
FastLED.show();
}
}
Here is my attempt at incorporating a button. Unfortunately its not working. I am trying to declare my functions below the void loop.
Code:
#include <FastLED.h>
#define BUTTON_PIN 3 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
#define NUM_LEDS_core 60
#define NUM_LEDS_arm 54
CRGB coreLeds[NUM_LEDS_core];
CRGB armLeds[NUM_LEDS_arm];
CRGBPalette16 gPal;
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
FastLED.addLeds<NEOPIXEL, 10>(coreLeds, NUM_LEDS_core);
FastLED.addLeds<NEOPIXEL, 17>(armLeds, NUM_LEDS_arm);
}
void loop() {
// Get current button state.
bool 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) {
showType++;
if (showType > 9)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: R1; // Black/off
break;
case 1: R2;
break;
}
}
void R1 ()
{
//ARMS
fadeToBlackBy( armLeds, NUM_LEDS_arm, 8);
byte dothue = 10;
for( int i = 0; i < 8; i++) {
armLeds[beatsin16( i+0, 0, NUM_LEDS_arm )] |= CHSV(dothue, 250, 80);
dothue += 22;
}
//CORE
for(int led = 0; led < NUM_LEDS_core; led++) {
coreLeds[led] = CRGB::Green;
}
FastLED.show();
}
void R2 ()
{
//ARMS
fadeToBlackBy( armLeds, NUM_LEDS_arm, 8);
byte dothue = 100;
for( int i = 0; i < 8; i++) {
armLeds[beatsin16( i+0, 0, NUM_LEDS_arm )] |= CHSV(dothue, 250, 80);
dothue += 22;
}
//CORE
for(int led = 0; led < NUM_LEDS_core; led++) {
coreLeds[led] = CRGB::Red;
}
FastLED.show();
}
any help most appreciated.