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();
}
}
}