#include <FastLED.h>
#define buttonOldinga 4
#define buttonOrqaga 5
#define LED_PIN 13
#define NUM_LED 8
int button_pressed_count = 0;
int button_state = 0;
int button_stateorqa = 0;
int oldi_button_state = 0;
int orqa_button_state = 0;
long interval=500;
long previousMillis=0;
CRGB leds[NUM_LED];
void setup() {
Serial.begin(9600);
pinMode(buttonOldinga, INPUT_PULLUP);
pinMode(buttonOrqaga, INPUT_PULLUP);
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LED);
Serial.println("Button count");
}
void offAllLeds(){
for(int i=0; i<8; i++){
leds[i] = CRGB(0,0,0);
}
}
void onLed(int led){
for(int i=0; i<8; i++){
if(led == i){
leds[i] = CRGB::Green;
}
}
}
void loop() {
button_state = digitalRead(buttonOldinga);
button_stateorqa = digitalRead(buttonOrqaga);
if(button_state != oldi_button_state){
if(button_state == HIGH ){
digitalWrite(13, LOW);
}else{
digitalWrite(13, HIGH);
button_pressed_count++;
Serial.println(button_pressed_count);
}
delay(50);
}
if(button_stateorqa != orqa_button_state){
if(button_stateorqa == LOW){
digitalWrite(13, HIGH);
} else{
digitalWrite(13, LOW);
button_pressed_count--;
}
delay(50);
}
oldi_button_state = button_state;
orqa_button_state = button_stateorqa;
if(button_pressed_count%14==0){
offAllLeds();
}
if(button_pressed_count%28==0){
onLed(0);
}else if(button_pressed_count%14==0){
onLed(8);
}
if(int (button_pressed_count/14)%2==1){
onLed(7-int((button_pressed_count%14)/2));
}else{
onLed(int((button_pressed_count%14)/2));
}
// if((buttonPin)==HIGH){
// button_pressed_count+=1;
// delay(500);
// }
if(button_pressed_count%2==1){
unsigned long currentMillis=millis();
if(currentMillis - previousMillis > interval){
previousMillis=currentMillis;
int curred_led;
if(button_pressed_count%28>14){
curred_led=7-int(button_pressed_count%14/2)-1;
}else{
curred_led=int(button_pressed_count%14/2)+1;
}
if(leds[curred_led]==HIGH || leds[curred_led]==LOW){
leds[curred_led] = CRGB::Red;
}else{
leds[curred_led] = CRGB(0,0,0);
}
}
}
FastLED.show();
// delay(100);
}