FastLED WS2812B ATtiny85 color change with button

Hello! I am working with ATtiny85 and ws2812b leds. I want to control the led color with button when pressed, but i cant figure out why nothing is working. The leds stays in single color. Can some one help?

The code:

#include <EEPROM.h>
#include <FastLED.h>

#define LED_PIN 0
#define NUM_LEDS 2
#define BUTTON_PIN 1
#define EEPROM_ADDR 0

CRGB leds[NUM_LEDS];
int mode = 0;

void makeStripe() {
switch (mode) {
case 0: leds[0] = CRGB(0, 0, 0); break; //balts
case 1: leds[0] = CRGB(255, 0, 0); break; //sarkans
case 2: leds[0] = CRGB(0, 255, 0); break; //zals
case 3: leds[0] = CRGB(0, 0, 255); break; //zils
case 4: leds[0] = CRGB(100, 0, 200); break; //violets
case 5: leds[0] = CRGB(35, 40, 210); break; //zilgans
case 6: leds[0] = CRGB(255, 255, 128); break; //dzeltens
case 7: leds[0] = CRGB(255, 180, 0); break; //orandzs
case 8: leds[0] = CRGB(255, 140, 180); break; //roza
}
}

void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812, LED_PIN, GBR>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
pinMode(BUTTON_PIN, INPUT_PULLUP);
FastLED.clear();

// nolasa no eeprom
mode = EEPROM.read(EEPROM_ADDR);
}

void loop() {
static bool buttonOld = 1;
bool state = digitalRead(BUTTON_PIN);

if (buttonOld != state) {
delay(200);
buttonOld = state;
if (state == 0) {
// saglaba ieprieksejo krasu
EEPROM.write(EEPROM_ADDR, mode);
mode = mode + 1;
mode = mode % 9;

  // Set the LED color based on the new mode value
  makeStripe();
  
  FastLED.show();
}

}
}

You might want to look at this How to get the best from this from this Forum before you proceed any further.

It tells you how to post code correctly here. It also requests that you post a schematic so we can fully understand your setup. In embedded computing code is only half the story.

I can't see what the EEPROM is doing for you in this sketch, you seem to be writing to it all the time, a very good way of wearing it out. An EEPROM has a limited number of writes it can take before it dosn't work any more, which while the number is large, it can easily be exceeded if the writes are in the loop function as this runs very frequently.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.