First time posting, I have tried my best over the last year to just read the forums/sites to find and learn answers. However this one has me stumped. I am sure it's a simple solution, but I can't seem to figure it out.
I have a fairly simple sketch. Using arduino nano, I have 2 buttons, and 2 led strips. The first strip has 6 led's, the second strip isn't really a strip, its just a single led cut from a strip.
Anyway, the intent was that the first button would cycle through some FastLED effects on the 6 led strips. The second button would change the color of the single led.
I am using eeprom.get and eeprom.put to hold the values for the 2 buttons. I have address 0,x for the cycle effects, and address 1,x for the color effects.
Both are working great independently, and doing the desired effect. The issue I am having, is that when the first button(cycle the effects) gets to its ">4" and resets to "0,0" it is also resetting the single led to "1,0".
#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 6
#define NUM_LEDS2 1
CRGB leds[NUM_LEDS];
CRGB leds2[1];
#define DATA_PIN 6
#define DATA_PIN2 8
#define BUTTON 2
#define BUTTON2 3
byte selectedEffect=0;
byte selectedColor=0;
void setup()
{
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2811, DATA_PIN2, GRB>(leds2, NUM_LEDS2).setCorrection( TypicalLEDStrip );
pinMode(2,INPUT_PULLUP); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
pinMode(3,INPUT_PULLUP); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON2), changeColor, CHANGE);
leds[0]= CHSV( HUE_BLUE, 255, 200);;
leds[1]= CHSV( HUE_RED, 255, 200);;
leds[2]= CHSV( HUE_GREEN, 255, 200);;
leds[3]= CHSV( HUE_YELLOW, 255, 200);;
leds[4]= CHSV( 255, 0, 200);;
leds[5]= CHSV( HUE_PURPLE, 255, 200);;;
Serial.begin(9600);
}
void loop() {
EEPROM.get(0,selectedEffect);
if(selectedEffect>4) {
selectedEffect=0;
EEPROM.put(0,0);
}
EEPROM.get(1,selectedColor);
if(selectedColor>5) {
selectedColor=0;
EEPROM.put(1,0);
}
switch(selectedColor){
case 0 : {
red();
break;
}
case 1 : {
green();
break;
}
case 2 : {
blue();
break;
}
case 3 : {
white();
break;
}
case 4 : {
purple();
break;
}
case 5 : {
yellow();
break;
}
}
switch(selectedEffect) {
case 0 : {
pulse();
break;
}
case 1 : {
allbright();
break;
}
case 2 : {
Eyes();
break;
}
case 3 : {
CylonBounce();
break;
}
}
}
void changeEffect() {
if (digitalRead (BUTTON) == HIGH) {
selectedEffect++;
EEPROM.put(0, selectedEffect);
asm volatile (" jmp 0");
}
}
void changeColor() {
if (digitalRead (BUTTON2) == HIGH) {
selectedColor++;
EEPROM.put(1, selectedColor);
asm volatile (" jmp 0");
}
}
void green(){
leds2[0] = CHSV( HUE_GREEN, 255, 200);
}
void red(){
leds2[0] = CHSV( HUE_RED, 255, 200);
}
void blue(){
leds2[0] = CHSV( HUE_BLUE, 255, 200);
}
void white(){
leds2[0] = CHSV( 255, 0, 200);;
}
void purple(){
leds2[0] = CHSV( HUE_PURPLE, 255, 200);
}
void yellow(){
leds2[0] = CHSV( HUE_YELLOW, 255, 200);
}
void pulse(){
int randelay = random(200,1000);
leds[0]= CHSV( HUE_BLUE, 255, 150);;
leds[1]= CHSV( HUE_RED, 255, 150);;
leds[2]= CHSV( HUE_GREEN, 255, 150);;
leds[3]= CHSV( HUE_YELLOW, 255, 150);;
leds[4]= CHSV( 255, 0, 150);;
leds[5]= CHSV( HUE_PURPLE, 255, 150);;;
FastLED.show();
delay(randelay);
int ranpixel = random(6);
leds[ranpixel].maximizeBrightness();
FastLED.show();
delay(100);
}
void Eyes() //
{
for(int eyebrightness=10; eyebrightness<255; eyebrightness++){
leds[0]= CHSV( HUE_BLUE, 255, eyebrightness);;
leds[1]= CHSV( HUE_RED, 255, eyebrightness);;
leds[2]= CHSV( HUE_GREEN, 255, eyebrightness);;
leds[3]= CHSV( HUE_YELLOW, 255, eyebrightness);;
leds[4]= CHSV( 255, 0, eyebrightness);;
leds[5]= CHSV( HUE_PURPLE, 255, eyebrightness);;;
FastLED.show(); //Update LED display
delay(10);
}
for(int eyebrightness=255; eyebrightness>=10; eyebrightness--)
{
leds[0]= CHSV( HUE_BLUE, 255, eyebrightness);;
leds[1]= CHSV( HUE_RED, 255, eyebrightness);;
leds[2]= CHSV( HUE_GREEN, 255, eyebrightness);;
leds[3]= CHSV( HUE_YELLOW, 255, eyebrightness);;
leds[4]= CHSV( 255, 0, eyebrightness);;
leds[5]= CHSV( HUE_PURPLE, 255, eyebrightness);;;
FastLED.show(); //Update LED display
delay(10);
}
}
void allbright() {
leds[0].maximizeBrightness();
leds[1].maximizeBrightness();
leds[2].maximizeBrightness();
leds[3].maximizeBrightness();
leds[4].maximizeBrightness();
leds[5].maximizeBrightness();
FastLED.show();
}
void CylonBounce(){
for(int i = 0; i < NUM_LEDS; i++) {
FastLED.setBrightness(100);
leds[i].maximizeBrightness();
FastLED.show();
delay(200);
}
delay(200);
for(int i = NUM_LEDS; i > 0; i--) {
leds[i].fadeLightBy(155);
FastLED.show();
delay(200);
}
delay(200);
}
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();
}