Stopping an audio switching loop

I've been writing a piece of code to change the behaviour of an audio switch which includes muting.
It is essential that the mute circuit is driven HIGH while the relay switches, and for my first mode in the example the relay must be starting LOW.

When running the code, the mute circuit will not stop blinking, however I want it to only run once upon mode change. Any suggestions? Thanks

//this is fine as the mode changes and the relay is driven LOW to prepare for input.
if ((position1 == LOW) && (position2 == HIGH) && (position3 == HIGH)){
  mode1(); 
  digitalWrite(relay, LOW);}

  
//this is not, as the relay requires the mute circuit to switch but will not stop blinking.
if ((position1 == LOW) && (position2 == HIGH) && (position3 == HIGH)){
  mode1();
  digitalWrite(mute, HIGH);
  delay(30); 
  digitalWrite(relay, LOW);
  delay(30);
  digitalWrite(mute, LOW);}

It looks like you need to detect when the conditions become true rtaher than when they are true. See the StateChangeDetection example in the IDE

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