2 switches one button ?

hwy peeps so im trying to make it so when switch 1 is "high" and Switch 2 is LOW and the button is pressed then LED == HIGH

For example,

hard to explain so i want so if one switch is on and the other is off and i press the button then the led will be on while the button is pressed

and if its the other way around switch 1 is off and switch 2 is on the led will "blip" when the button is pressed ,

sorry for the Very bad code setup im testing it in the Tinkercad circuit, what ever i do i cant seem to get it to work?

int Mswitch1 = 5;
int Tog1 = 2;
int Tog2 = 3;
int snd = 4;
unsigned long startTime = millis();
int T1 = 0;
//---------------------------------------------------------------
void setup() {
   Serial.begin(9600);
  // digitalWrite(switchPin, HIGH);
 pinMode(Mswitch1,INPUT);
 pinMode(Tog1, INPUT);
 pinMode(Tog2, INPUT);
  pinMode(snd, OUTPUT);
}
//-----------------------------------------------------------------
void loop() {
  // ---------------------------
  if (digitalRead(Tog1) == HIGH){
    T1 = 1;
   if (digitalRead(Tog2) == HIGH){
     T1 = 2;
  }
  }
//-----------------------------

  // ---------------------------
  if (digitalRead(Tog2) == HIGH){
    
    T1 = 2;
  }
//-----------------------------

//  if ((digitalRead(Mswitch1) == HIGH)){
 //  digitalWrite(snd, HIGH);
  //  Serial.println(T1 && "1");
  //   T1 = 0;
  //  digitalWrite(snd,LOW);
 // }
  
  
  
// if ((digitalRead(Mswitch1) == HIGH) && (T1 == 1)
  // ---------------------------
  if ((digitalRead(Mswitch1) == HIGH) && (T1 == 1)){
   digitalWrite(snd, HIGH);
     T1 = 0;
   //erial.println(T1 && "1");
  }
  
  // ---------------------------
 if ((digitalRead(Mswitch1) == HIGH) && (T1 == 2)){
delay(1000);
   
while ( digitalRead(Mswitch1) == HIGH && millis() < (startTime + 100) && (T1 = 1)) {
    digitalWrite(snd, HIGH);
   //  Serial.println(T1 && "2");
     T1 = 0;
    }
    
  
  }
//-----------------------------

}

void callMillis(unsigned long x)
{
  unsigned long presentMillis = millis();
  while (millis() - presentMillis != x)
  {
//============ End Void callmillis ============
  }
}
//----------------------------------------------------------------

I started Again and think iv sorted it with this :

int B = 2;
int T1 = 3;
int T2 = 5;
int L = 4;
void setup()
{
pinMode(B, INPUT);
pinMode(T1, INPUT);

pinMode(L, OUTPUT);
}

void loop()
{

if ((digitalRead(B) == HIGH)&& (digitalRead(T2) == HIGH)){

digitalWrite (L, HIGH);
delay(200);
digitalWrite (L, LOW);
// digitalWrite(snd, HIGH);
}
if ((digitalRead(B) == HIGH)&& (digitalRead(T1) == HIGH)){

digitalWrite (L, HIGH);
delay(200);
digitalWrite (L, LOW);
// digitalWrite(snd, HIGH);
}
}

Nowm one last bit and i think its done, how do i make the LED Turn on for a specific time for example 500ms and turn off while the button is still pressed?

Fixed it with this

if ((digitalRead(B) == HIGH)&& (digitalRead(T1) == HIGH)){
delay(50);
digitalWrite(L, HIGH );
while ( digitalRead(B) == HIGH && millis() < (startTime + 1000000)){

delay(50);
digitalWrite(L, LOW );

Thanks Everyone Sorted it all now, time to upload and test :stuck_out_tongue:

You should never add to a millis() values, only ever subtract...

 while ( digitalRead(B) == HIGH && millis() - startTime < 1000000 ){

Your code snippet doesn’t show where you set startTime.

1000000 ms = 1000 s = approx 16.6 minutes
Not quite sure how a delay of that length would “fix” anything.

Edit: Code tags look like this... [​code][​/code]
They can be inserted via the </> button on the toolbar.
Please use them when posting code to the forums.