// PinMode
int _PinMode_LED[] = {2, 3, 4, 5, 6};
int _PinMode_Buttons[] = {7, 8};
// Integer used in Loops
int i;
// Length of PinMode Arrays
int Length_PinMode_LED;
int Length_PinMode_Buttons;
// Button states
int ButtonState1 = LOW;
int ButtonState2 = LOW;
bool Pattern1 = false;
bool Pattern2 = false;
// Managing the states
int LastButtonState1 = LOW;
int LastButtonState2 = LOW;
/*int reading1;
int reading2;*/
void setup() {
Serial.begin(9600);
Length_PinMode_LED = sizeof(_PinMode_LED) / sizeof(_PinMode_LED[0]);
Serial.println(Length_PinMode_LED);
Length_PinMode_Buttons = sizeof(_PinMode_Buttons) / sizeof(_PinMode_Buttons[0]);
Serial.println(Length_PinMode_Buttons);
for (int i = 0; i < Length_PinMode_LED; i++) {
pinMode(_PinMode_LED[i], OUTPUT);
}
for (int i = 0; i < Length_PinMode_Buttons; i++) {
pinMode(_PinMode_Buttons[i], INPUT);
}
}
void loop() {
// checking the state of the buttons
ButtonState1 = digitalRead(_PinMode_Buttons[0]);
ButtonState2 = digitalRead(_PinMode_Buttons[1]);
if(digitalRead(_PinMode_Buttons[0]) == HIGH && LastButtonState1 == LOW)
{
Example1();
}
else{
if(digitalRead(_PinMode_Buttons[1]) == HIGH && LastButtonState2 == LOW)
{
Example2();
}
if(digitalRead(_PinMode_Buttons[1] == LOW && LastButtonState2 == HIGH))
{
CloseLights();
}
LastButtonState1 = ButtonState1;
LastButtonState2 = ButtonState2;
}
/*if (Pattern1) {
CloseLights();
Example1();
} else if (Pattern2) {
CloseLights();
delay(500);
Example2();
} else {
CloseLights(); }*/
}
void Example1() {
for (int i = 0; i < Length_PinMode_LED; i++) {
digitalWrite(_PinMode_LED[i], HIGH);
delay(500);
if (i == Length_PinMode_LED - 1) {
for (int x = 0; x <= Length_PinMode_LED; x++) {
digitalWrite(_PinMode_LED[abs(x - Length_PinMode_LED)], LOW);
delay(500);
}
}
}
}
void Example2() {
for (int i = 0; i < Length_PinMode_LED; i++) {
digitalWrite(_PinMode_LED[i], HIGH);
}
delay(500);
for (int i = 0; i < Length_PinMode_LED; i++) {
digitalWrite(_PinMode_LED[i], LOW);
}
}
void CloseLights() {
for (int i = 0; i < Length_PinMode_LED; i++) {
digitalWrite(_PinMode_LED[i], LOW);
}
}