const int LEDs[] = { 7 , 6 , 5 , 4 , 3 , 2, 8 };
const int ledStripSize = sizeof(LEDs) / sizeof(LEDs[0]);
const int startingPosition = 0;
//intialising the current position
int currentPosition;
typedef void (*callbackFunction)();
//button shit here
const int button = 12;
int lastValueOfBtn = HIGH;
void setup() {
Serial.begin(115200);
pinMode(button , INPUT_PULLUP);
// set all of the led pin modes to HIGH
for(int i = 0 ; i < ledStripSize ; i++){
pinMode(LEDs[i] , OUTPUT);
}
//check if the starting postion is out of bounds
if(startingPosition <= ledStripSize - 1){
currentPosition = startingPosition;
}
else{
Serial.println("Starting Position is out of bounds , Setting The Default Current Postion to 0");
currentPosition = 0;
}
//turning the light on starting position
blinkLED();
}
void loop() {
// repeat(moveRight , 6);
// repeat(moveLeft , 6);
int currentValueOfBtn = digitalRead(button);
if(currentValueOfBtn == LOW){
moveRight();
};
if(currentValueOfBtn != lastValueOfBtn){
if(currentValueOfBtn == HIGH){
if(currentPosition < ledStripSize - 1){
//restart it
currentPosition = 0;
for(int i = 1 ; i < ledStripSize ; i++){
digitalWrite(LEDs[i] , LOW);
}
}
if(currentPosition == ledStripSize - 1){
for(int i = 0 ; i < ledStripSize ; i++){
for(int j = 0 ; j < 2 ; j++){
digitalWrite(LEDs[i] , LOW);
delay(200);
digitalWrite(LEDs[i] , HIGH);
delay(200);
}
}
//clear all
for(int i = 1 ; i < ledStripSize ; i++){
digitalWrite(LEDs[i] , LOW);
currentPosition = 0;
}
}
};
lastValueOfBtn = currentValueOfBtn;
}
}
bool moveRight(){
//handling out of range errors
if(currentPosition < ledStripSize - 1 ){
currentPosition++;
blinkLED();
return true;
}
else{
Serial.println("Right is out of bounds");
blinkLED();
return false;
};
}
bool moveLeft(){
if(currentPosition > 0 ){
currentPosition--;
blinkLED();
return true;
}
else{
Serial.println("Left is out of bounds");
blinkLED();
return false;
};
}
void blinkLED(){
digitalWrite(LEDs[currentPosition] , HIGH);
Serial.println(currentPosition);
delay(500);
// digitalWrite(LEDs[currentPosition] , LOW);
// delay(500);
}
void repeat(callbackFunction callback , int times){
for (int i = 0 ; i < times ; i++){
callback();
}
}