//definding all the variables and arrays for the code
#define max_array 1000
unsigned int arr_lenght = 0;
int randLed[15];
int buttons[] = {50, 49, 48, 47, 46, 45, 44, 43, 42, 15};
int leds[] = {10, 9, 8, 7, 6, 5, 4, 3, 2};
int good = 20;
int bad = 21;
//int checkButton = 15;
byte index = 10;
byte greenLed = 20;
byte redLed = 21;
const unsigned long dealyTime = 50;
unsigned long pastTime = 0;
long randomNum;
byte pressed;
bool halo = true;
void setup() {
//making all the necesarry pinMode settings
for (int led : leds) {
pinMode(led, OUTPUT);
}
for (int button : buttons) {
pinMode(button, INPUT_PULLUP);
}
pinMode(good, OUTPUT);
pinMode(bad, OUTPUT);
}
/*
int indexOf(int lista[], int led, int sizeofList = 9) {
for (int listaIndex = 0; listaIndex < sizeofList; ++listaIndex) {
if (digitalRead(lista[listaIndex]) == LOW) {
return listaIndex;
}
}
return sizeofList + 1;
}
*/
int buttonPressed = 0;
int indexLed = 0;
void randomLed() {
//making a function for random leds
//its only blinking a random led after you pressed the button
for (int button : buttons) {
pressed = digitalRead(button);
if (digitalRead(15) == (LOW || pressed == LOW) && halo) {
randomSeed(analogRead(A1));
randomNum = random(2, 10);
digitalWrite(randomNum, HIGH);
delay(500);
digitalWrite(randomNum, LOW);
randLed[arr_lenght] = randomNum;
arr_lenght++;
halo = false;
}
index -= 1;
}
index = 10;
//checking if the button is pressed and storing it
}
void action() {
unsigned long currentTime = millis();
if (currentTime - pastTime >= dealyTime) {
//go through all the buttons, check them one by one if they pressed or not
//if yes, make that led's state HIGH that is the same indexed element of the leds array
int act_butt;
for (int button : buttons) {
digitalWrite(index, !digitalRead(button));
index -= 1;
if (digitalRead(button) == LOW) {
act_butt = button;
}
}
if (randLed[-1] == act_butt) {
digitalWrite(good, HIGH);
delay(100);
digitalWrite(good, LOW);
halo = true;
}
else {
digitalWrite(bad, HIGH);
delay(100);
digitalWrite(bad, LOW);
}
index = 10;
pastTime = currentTime;
}
}
void loop() {
randomLed();
action();
/*for (int led : randLed) {
digitalWrite(led, HIGH);
}*/
}