Make a function repeatable (with button)(continued)

Hi. I am causing a lot of trouble, aren't I?
I ran out of "replies" Here is what I would like the code to do.

here is the code for the above:

// RED ALERT Button
//turns off spots 1-7, turns on red LEDs. 10 seconds, turns on 1-t in sequence 500ms apart
//red LEDs turn off
//This only works once when powered on.


//setup LED pins for spots
int dryDock1 = 23;
int dryDock2 = 25;
int dryDock3 = 27;
int dryDock4 = 29;
int dryDock5 = 31;
int dryDock6 = 33;
int dryDock7 = 35;

//Red Alert lights and relay
int redPin1 = 50;
int redPin2 = 52;
int relayPin = 48;

//assign states
int redState = 0;
int redLength = 10000;


int redSwitch = 28;

// time intervals between lights on
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 (;;) {}
//    redState =digitalRead(redSwitch);
//    millis();//redState =!redState;
//    previousTime = currentTime;
  } else
  { }
  //

}

What do you mean by this ?

CROSSPOST alert! Check your original thread for replies! There are lots of them.

@UKHeliBob

Maybe they meant “edits” which has happened to me a few times.

Take LarryD's hint and look at the State change detection example that comes with the IDE.

Copy it and when you detect a button press, save millis to your variable and set a boolean that says DoDockingBaySequence to true. Print a message to serial about it.

Get that working and you're most of the way there.

@LarryD and @wildbill: may I suggest we encourage the OP to continue this discussion in his original thread?

Yes the OP should stay with the 1st post.

However, it might be a problem with the new software.

Not sure if there is a limit on the number of posts or replies or edits new people are allowed.

If it is the new software then it sure kicks the :poop: out of communications.

1 Like

@smacks999
If you give me details of his problem with running out of replies I will take the necessary action if the forum software lets me

1 Like

Thanks, UKHelibob. When I tried to reply again to the thread, a popup appeared saying something ike "We value your enthusiasm, but because you are a new member, you are limited to 20 (something) replies in an 8 hour period. So I had to wait and stupidly cross-threaded, I am not sure if I can delete that one, as I tried but there seems no mechanism for the poster to do so.--
--Jim

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.