Hi I have tried my best to get this code to start with a button push. I am hoping to be able to repeat the sequence with a button push at any time.
I am building a model. There are several lights on. when the button is pushed, I want the code to run-turn off some lights, turn others on at the same time, than after 10 seconds (or so), the lights come back on one at a time, the others just turned on go off. This code works the way I want it on my Arduino Mega. But i have tried all kinds of button codes, libraries and made up stuff, but it won't go. The primary problem is the timing trigger that I want to start with the button goes no matter if the button is pushed or not. I am stuck. This looks like it should be so easy, but there is something that I am just not getting.
This is the code that I worked out. (The "drydock" LEDs should be in an array, but one step at a time.) You can see things that I have tried commented out). I also know that the redundant "redPin"s need not be there. Thanks.
// Enterprise Refit Red Alert Sequence
int dryDock1 = 23; //floodlights
int dryDock2 = 25;
int dryDock3 = 27;
int dryDock4 = 29;
int dryDock5 = 31;
int dryDock6 = 33;
int dryDock7 = 35;
int redPin1 = 50; //red alert lights
int redPin2 = 52;
int redSwitch = 28;
int relayPin = 48;//relay
int redState = 1;
int redLength = 11000;
const unsigned long eventInterval0 = 10000;
const unsigned long eventInterval1 = 11000;
const unsigned long eventInterval2 = 11500;
const unsigned long eventInterval3 = 12000;
const unsigned long eventInterval4 = 12500;
const unsigned long eventInterval5 = 13000;
const unsigned long eventInterval6 = 13500;
const unsigned long eventInterval7 = 14000;
unsigned long previousTime = 0;
unsigned long currentTime = 0;
void setup() {
Serial.begin(9600);
pinMode(redPin1, OUTPUT);
pinMode(redPin2, OUTPUT);
pinMode(dryDock1, OUTPUT);
pinMode(dryDock2, OUTPUT);
pinMode(dryDock3, OUTPUT);
pinMode(dryDock4, OUTPUT);
pinMode(dryDock5, OUTPUT);
pinMode(dryDock6, OUTPUT);
pinMode(dryDock7, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(redSwitch, INPUT);
}
void loop() {
// redState = digitalRead(redSwitch); // check if button is pushed
// if (redState == HIGH)
currentTime = millis();
if (currentTime <= redLength)
{
digitalWrite(redPin1, HIGH);
digitalWrite(redPin2, HIGH);
digitalWrite(relayPin, HIGH);
digitalWrite(dryDock1, LOW);
digitalWrite(dryDock2, LOW);
digitalWrite(dryDock3, LOW);
digitalWrite(dryDock4, LOW);
digitalWrite(dryDock5, LOW);
digitalWrite(dryDock6, LOW);
digitalWrite(dryDock7, LOW);
}
if (currentTime = millis())
// previousTime = currentTime;
/* Updates frequently */
// digitalWrite(redPin1, LOW);
// digitalWrite(redPin2, LOW);
// digitalWrite(relayPin, LOW);
if (currentTime >= eventInterval1)
{
Serial.println("Ice Ice Baby1");
{ digitalWrite(redPin1, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(relayPin, LOW);
digitalWrite(dryDock1, HIGH);
}
/* Update the timing for the next time around */
// previousTime = currentTime;
}
/* This is the event */
if (currentTime >= eventInterval2) {
/* Event code */
Serial.println("Ice Ice Baby2");
//digitalWrite(dryDock1, HIGH);
digitalWrite(dryDock2, HIGH);
digitalWrite(redPin1, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(relayPin, LOW);
}
/* Update the timing for the next time around */
// previousTime = currentTime;
/* This is the event */
if (currentTime >= eventInterval3) {
/* Event code */
Serial.println("Ice Ice Baby3");
digitalWrite(dryDock3, HIGH);
digitalWrite(redPin1, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(relayPin, LOW);
}
/* Update the timing for the next time around */
// previousTime = currentTime;
/* This is the event */
if (currentTime >= eventInterval4) {
/* Event code */
Serial.println("Ice Ice Baby4");
digitalWrite(dryDock4, HIGH);
digitalWrite(redPin1, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(relayPin, LOW);
}
/* Update the timing for the next time around */
// previousTime = currentTime;
/* This is the event */
if (currentTime >= eventInterval5) {
/* Event code */
Serial.println("Ice Ice Baby5");
digitalWrite(dryDock5, HIGH);
digitalWrite(redPin1, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(relayPin, LOW);
}
/* Update the timing for the next time around */
// previousTime = currentTime;
if (currentTime >= eventInterval6) {
/* Event code */
Serial.println("Ice Ice Baby6");
digitalWrite(dryDock6, HIGH);
digitalWrite(redPin1, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(relayPin, LOW);
}
/* Update the timing for the next time around */
// previousTime = currentTime;
if (currentTime >= eventInterval7) {
/* Event code */
Serial.println("Ice Ice Baby7");
digitalWrite(dryDock7, HIGH);
digitalWrite(redPin1, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(relayPin, LOW);
Serial.println("end");
for (;;) {}
} else
{ }
//
}

