i want to learn more
Good because that is appalling code, let me show you how start to do it better.
You have each LED pin defined as a separate variable:-
const int led0 = 3;
const int led1 = 4;
const int led2 = 5;
const int led3 = 6;
const int led4 = 7;
const int led5 = 8;
const int led6 = 9;
const int led7 = 10;
const int led8 = 11;
const int led9 = 12;
const int led10 = 13;
const int led11 = 14;
const int led12 = 15;
const int led13 = 16;
const int led14 = 17;
const int led15 = 18;
now a minor point is that an int is two bytes and you can save a bit of memory by using a byte type variable. But the big problem with this is that you have a fixed name variable for each LED pin. If you could make that variable a variable then you can shorten the code considerably. You do this by making an array.
byte ledPin[] = { 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
Now the value of ledPin[0] is 3, the value of ledPin[1] is 4,and so on. But the big thing is that the number inside the square brackets can be a variable, so if you want to do something to all the LEDs then put that in a for loop. For example:-
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10,OUTPUT);
pinMode(led11,OUTPUT);
pinMode(led12, OUTPUT);
pinMode(led13, OUTPUT);
pinMode(led14,OUTPUT);
pinMode(led15,OUTPUT);
Becomes simply
for(int i=0; i<16;i++){
pinMode(ledPin[i],OUTPUT);
}
In the same way
void loopspeedDwnRvs()
{ for (int loopspeed = 1 ; loopspeed <=101; loopspeed +=masterDelay) {
digitalWrite(led15, HIGH); delay(loopspeed);
digitalWrite(led15, LOW); delay(loopspeed);
digitalWrite(led14, HIGH); delay(loopspeed);
digitalWrite(led14, LOW); delay(loopspeed);
digitalWrite(led13, HIGH); delay(loopspeed);
digitalWrite(led13, LOW); delay(loopspeed);
digitalWrite(led12, HIGH); delay(loopspeed);
digitalWrite(led12, LOW); delay(loopspeed);
digitalWrite(led11, HIGH); delay(loopspeed);
digitalWrite(led11, LOW); delay(loopspeed);
digitalWrite(led10, HIGH); delay(loopspeed);
digitalWrite(led10, LOW); delay(loopspeed);
digitalWrite(led9, HIGH); delay(loopspeed);
digitalWrite(led9, LOW); delay(loopspeed);
digitalWrite(led8, HIGH); delay(loopspeed);
digitalWrite(led8, LOW); delay(loopspeed);
digitalWrite(led7, HIGH); delay(loopspeed);
digitalWrite(led7, LOW); delay(loopspeed);
digitalWrite(led6, HIGH); delay(loopspeed);
digitalWrite(led6, LOW); delay(loopspeed);
digitalWrite(led5,HIGH); delay(loopspeed);
digitalWrite(led5,LOW); delay(loopspeed);
digitalWrite(led4,HIGH); delay(loopspeed);
digitalWrite(led4,LOW); delay(loopspeed);
digitalWrite(led3,HIGH); delay(loopspeed);
digitalWrite(led3,LOW); delay(loopspeed);
digitalWrite(led2,HIGH); delay(loopspeed);
digitalWrite(led2,LOW); delay(loopspeed);
digitalWrite(led1,HIGH); delay(loopspeed);
digitalWrite(led1,LOW); delay(loopspeed);
digitalWrite(led0,HIGH); delay(loopspeed);
digitalWrite(led0,LOW); delay(loopspeed);}
}
Becomes:-
void loopspeedDwnRvs()
{
for (int loopspeed = 1 ; loopspeed <=101; loopspeed +=masterDelay) {
for(int i=0; i<16;i++){
digitalWrite(ledPin[i], HIGH);
delay(loopspeed);
digitalWrite(ledPin[i], LOW);
delay(loopspeed);
}// end of LED itteration
}// end of loopspeed
} // end of function
Now this bit in your loop function looks wrong to me:-
else {
digitalWrite(led0, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);}
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10,HIGH);
digitalWrite(led11,HIGH);
digitalWrite(led12,HIGH);
digitalWrite(led13,HIGH);
digitalWrite(led14,HIGH);
digitalWrite(led15,HIGH);
LEDs 0 to 7 get set HIGH as a result of the test on the button state failing but LEDs 8 to 15 get set HIGH every time round the loop. Is that what you want here?
OK so go through your code and try and shorten it, remember loops can count forward as well as backward, but functions like your zigzag will need another layer of arrays so don't worry about that for now, I will show you how to do that once you have used this principle to make most of your code bearable to read.