Hello. I am building a LED light tower, kind of like a drag strip light. It would have 4 or 5 LEDs across 12 rows. The top row would be a "get ready" row. then would be 10 countdown rows (3 seconds each would be a 30 second game), and the 12th row would be "Game OVER" with lights and a buzzer.
My plan is to have the tower in "demo mode", run by a toggle switch on one of the analog inputs, where it would have a loop lasting about 3 seconds (each output for .25 seconds) for the tower to go from top to bottom over and over. Then when the toggle is swiched, the sketch would go into a if/then for a second part of the sketch.
This part would hold the output on Digital 13 (Arduino uno board) on high until a momentary button (also on an analog input) is pushed. Then, each of the digital inputs 12 to 3 would go three second each until it reaches digital 2, where it holds for 10 seconds, then returns back to digital 13, waiting to see if the push button is pushed again.
I have he following sketch for just the push button part, as I figured I needed to get that part done first, but I can not get the lights to respond to the analog input. As soon as I load the sketch, it just starts the count down, and just loops over and over, never waiting for the button.
/*
Tower Programming, user can do whatever they would like with this sketch
*/
//Variable Definitions
const int Trigger = 14; //Assigns anlog pin A0 as Digial Pin 14
const int LEDRow12 = 13; //Assigns Digital Pin 13 as LED Row 12
const int LEDRow11 = 12; //Assigns Digital Pin 12 as LED Row 11
const int LEDRow10 = 11; //Assigns Digital Pin 11 as LED Row 10
const int LEDRow9 = 10; //Assigns Digital Pin 10 as LED Row 9
const int LEDRow8 = 9; //Assigns Digital Pin 9 as LED Row 8
const int LEDRow7 = 8; //Assigns Digital Pin 8 as LED Row 7
const int LEDRow6 = 7; //Assigns Digital Pin 7 as LED Row 6
const int LEDRow5 = 6; //Assigns Digital Pin 6 as LED Row 5
const int LEDRow4 = 5; //Assigns Digital Pin 5 as LED Row 4
const int LEDRow3 = 4; //Assigns Digital Pin 4 as LED Row 3
const int LEDRow2 = 3; //Assigns Digital Pin 3 as LED Row 2
const int LEDRow1 = 2; //Assigns Digital Pin 2 as LED Row 1
int TriggerState = 0; //Initial State of the Trigger Button
int LastButtonState = 0; // the previous reading from the input pin
int TriggerCount = 0; //Initialize the Trigger Count as 0
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
//PinMode Setup
pinMode(Trigger, INPUT); //Assigns Tirgger Button Pin as Input
pinMode(LEDRow12, OUTPUT); //Assigns Pin 13 as Output
pinMode(LEDRow11, OUTPUT); //Assigns Pin 12 as Output
pinMode(LEDRow10, OUTPUT); //Assigns Pin 11 as Output
pinMode(LEDRow9, OUTPUT); //Assigns Pin 10 as Output
pinMode(LEDRow8, OUTPUT); //Assigns Pin 9 as Output
pinMode(LEDRow7, OUTPUT); //Assigns Pin 8 as Output
pinMode(LEDRow6, OUTPUT); //Assigns Pin 7 as Output
pinMode(LEDRow5, OUTPUT); //Assigns Pin 6 as Output
pinMode(LEDRow4, OUTPUT); //Assigns Pin 5 as Output
pinMode(LEDRow3, OUTPUT); //Assigns Pin 4 as Output
pinMode(LEDRow2, OUTPUT); //Assigns Pin 3 as Output
pinMode(LEDRow1, OUTPUT); //Assigns Pin 2 as Output
}//End Setup
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(Trigger);
digitalWrite(LEDRow12, HIGH);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != LastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != TriggerState) {
TriggerState = reading;
// only toggle the LED if the new button state is HIGH
if (TriggerState == HIGH) {
TriggerCount = TriggerCount +1;
}
}
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
LastButtonState = reading;
if (TriggerCount = 1) {
}
if (TriggerCount = 2){
digitalWrite(LEDRow12,LOW); //LED Off
digitalWrite(LEDRow11, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow11,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow10, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow10,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow9, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow9,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow8, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow8,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow7, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow7,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow6, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow6,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow5, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow5,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow4, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow4,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow3, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow3,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow2, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow2,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
digitalWrite(LEDRow1, HIGH); //LED On
LEDOnDelay(); //Length of Time LED will Stay On
digitalWrite(LEDRow1,LOW); //LED Off
LEDOffDelay(); //Length of Time Until Next LED Lights Up
delay(10000); //Ten Second Delay at End
TriggerCount = 0; //Resets Back to Loop to Wait for Next Trigger Press with LEDs Off
}
if (TriggerCount >2){ //I do not Know what will happen if they rapid push the button more than twice so I am canceling that out here.
TriggerCount = 0;
}
} //End Loop
void LEDOnDelay(){
delay(3000); //3 Second Delay
} //End LED On Delay
void LEDOffDelay(){
delay(1); //no Delay
} // End LED Off Delay
What am I missing, and how do I put in the demo mode with the toggle?