Hello everyone, im at a point in my programming where im stuck, the basis for the program is im building a traffic adviser for my truck, (the amber type that tells you left or right type of deal), it has 4 push buttons, button 1 activates the "warning mode" which is a fast and randomish pattern, button 2 activates a move left pattern, button 3 activates a go around pattern, and button 4 activates a move right pattern.
i have gotten each pattern to work with the assigned button, but the for loop only completes 1 cycle then i have to push the button again to get it to play again.
how do i get it to continuously play till either the button is pushed again to stop the pattern or another button is pushed to change the pattern?
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
int button1value = 0;
int button2value = 0;
int button3value = 0;
int button4value = 0;
int button1 = A5;
int button2 = A4;
int button3 = A3;
int button4 = A2;
boolean last1 = LOW;
boolean last2 = LOW;
boolean last3 = LOW;
boolean last4 = LOW;
boolean current1 = LOW;
boolean current2 = LOW;
boolean current3 = LOW;
boolean current4 = LOW;
//----------------------------------------------------------------------------
void setup() {
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
int ledPins[] = {11, 10, 9, 8, 7, 6, 5, 3, 2};
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], LOW); // turns all lights off
}
}
boolean debounce(boolean last1) {
boolean current1 = analogRead(button1);
if (last1 != current1) {
delay(5);
current1 = analogRead(button1);
}
return current1;
}
boolean debounce2(boolean last2) {
boolean current2 = analogRead(button2);
if (last2 != current2) {
delay(5);
current2 = analogRead(button2);
}
return current2;
}
boolean debounce3(boolean last3) {
boolean current3 = analogRead(button3);
if (last3 != current3) {
delay(5);
current3 = analogRead(button3);
}
return current3;
}
boolean debounce4(boolean last4) {
boolean current4 = analogRead(button4);
if (last4 != current4) {
delay(5);
current4 = analogRead(button4);
}
return current4;
}
//------------------------------------------------------------------------
void loop() {
int ledPins[] = {11, 10, 9, 8, 7, 6, 5, 3, 2}; //table with all leds
int ledPinscustom[] = {11, 10, 8, 7, 5, 3, 2}; //table with limited leds
int ledPinscustom2[] = {10, 9, 8, 7, 6, 5, 3}; //table with limited leds
current1 = debounce(last1);
if (last1 == LOW && current1 == HIGH)
{
//center 2 on outer 3 flash with center of 3 on.
for (int i = 0; i <= 8; i++) {
// digitalWrite(ledPins[i], LOW);
for (int j = 0; j <= 6; j++) {
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[6], LOW);
digitalWrite(ledPinscustom[j], HIGH);
}
delay(150);
for (int k = 0; k <= 6; k++) {
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[8], LOW);
digitalWrite(ledPinscustom2[k], HIGH);
}
delay(150);
} //end for loop
//Turns off all leds
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(150);// end for loop
//strobe, out to in, with 1 each side lit.
for (int i = 0; i <= 5; i++) {
for (int i = 0; i <= 4; i++) {
digitalWrite(ledPins[i], HIGH);
digitalWrite(ledPins[8 - i], HIGH);
delay(50);
digitalWrite(ledPins[i], LOW);
digitalWrite(ledPins[8 - i], LOW);
delay(50);
}
}//end for loop
//Turns off all leds
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(150);// end for loop
//half and half fast
for (int i = 0; i <= 8; i++) {
for (int i = 0; i <= 5; i++) {
digitalWrite(ledPins[i], HIGH);
}
for (int i = 5; i <= 8; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(100);
for (int i = 0; i <= 3; i++) {
digitalWrite(ledPins[i], LOW);
}
for (int i = 5; i <= 8; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(100);
}//end for loop
//Turns off all leds
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], LOW); //Turns on LED #i each time this runs
}
delay(150);// end for loop
//LEDs strobe, center out, 1 each side lit.
for (int i = 0; i <= 5; i++) {
for (int i = 5; i >= 0; i--) {
digitalWrite(ledPins[i ], HIGH); //Turns on LED #i each time this runs
digitalWrite(ledPins[8 - i], HIGH); //Turns on LED #i each time this runs
delay(50);
digitalWrite(ledPins[i ], LOW); //Turns on LED #i each time this runs
digitalWrite(ledPins[8 - i], LOW); //Turns on LED #i each time this runs
delay(50);
}
} //end for loop
}
last1 = current1;
current2 = debounce2(last2);
if (last2 == LOW && current2 == HIGH)
{
//slow arrow left to right
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], HIGH);
delay(500);
}
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], LOW); // turns all lights off
}
}
last2 = current2;
current3 = debounce3(last3);
if (last3 == LOW && current3 == HIGH)
{
for (int i = 4; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH); //Turns on LED #i each time this runs
digitalWrite(ledPins[8 - i], HIGH); //Turns on LED #i each time this runs
delay(500);
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], LOW); // turns all lights off
}
}
}
last3 = current3;
current4 = debounce4(last4);
if (last4 == LOW && current4 == HIGH)
{
//slow arrow right to left
for (int i = 8; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH);
delay(500);
}
for (int i = 0; i <= 8; i++) {
digitalWrite(ledPins[i], LOW); // turns all lights off
}
}
last4 = current4;
}
