One time switch state check

So I'm working on a program to incorporate a 555 functionality that is hooked to a toggle switch. The output pin pulses a set of 4015 shift registers to stack a series of LEDs in sequence. The toggle turns the blink function on, but I want to be able to depower the system with the ability to have the switch still set to high. When the system is repowered, I don't want the arduino to commence pulsing the 4015s. The user will need to toggle the switch to low, and then once it is toggled back to high, the sequence will start again.

My code so far looks like this

const int ledPin = 11;
const int switchPin = 2;
boolean switchPinCheck = true;

int led1State = LOW;
int switchPinState = 0;

long previous1Millis = 0;
long interval = 50;

void setup(){
    pinMode(ledPin, OUTPUT);
    pinMode(switchPin, INPUT);
    switchPinState = digitalRead(switchPin);
    if(switchPinState == HIGH)
      switchPinCheck = false;
}

void blink(long mod, int led, int *state, long *previous){

    unsigned long currentMillis = millis();
    
    if(currentMillis - *previous > interval/mod){
       *previous = currentMillis;
       
       if (*state == LOW)
         *state = HIGH;
       else
         *state = LOW;
         
    digitalWrite(led, *state);
    }
}

void loop() {
   switchPinState = digitalRead(switchPin);

   if(switchPinCheck == true){
      if(switchPinState == HIGH){
        blink(1, ledPin, &led1State, &previous1Millis);
       }
    }

    if(switchPinState == LOW)
      switchPinCheck = true; 
   
}

The idea is to use the boolean to decouple the blink function from the switch state until the user has cycled the switch.

Perhaps I should put the boolean true initialization within the setup routine as an if/else setup instead of only having the switch read set it to false?

Perhaps I should put the boolean true initialization within the setup routine as an if/else setup instead of only having the switch read set it to false?

Does it do what you want the way it is written? If so, leave it alone.

If not, keep f**king with it until it's completely broken.

are you overthinking it?

just turn on blink() on the change in the toggle switch:

fYI, millis() returns an unsigned long

const int ledPin = 11;
const int switchPin = 2;
boolean goBlink = false;

int led1State = LOW;
int lastSwitchPinState;

unsigned long previous1Millis = 0;
unsigned long interval = 50UL;
boolean somethingElse = false;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop() 
{
  int switchPinState = digitalRead(switchPin);
  if(switchPinState == HIGH && lastSwitchPinState == LOW)
  {
    goBlink = true;
  }
  lastSwitchPinState = switchPinState;
  if(goBlink) blink(1, ledPin, &led1State, &previous1Millis); 
  if (somethingElse)
  {
    goBlink = false;
  }
}
blink()
{
  // your blink function
}

Thanks Bulldog. I usually do overthink things >_> But your method works flawlessly. all I changed was the bit at the end where you included the boolean somethingElse and just used it as a switch state check again to set the goBlink to false when the switch goes low.

great. I just put somethingElse there as an example of a way to switch the state of blink() back...

glad to see you got it working.