If command not working

I am not able to get my code to bypass the special commands if the if statement is not met. See the following code.

//Basic Traffic Light}
int led1R = 2; // LED attached to pin 2
int led1Y = 3; 
int led1G = 4;
int led2R = 5;
int led2Y = 6;
int led2G = 7;
int ledT  = 8;
int pad = 10;
void setup() {
  pinMode(led1R, OUTPUT); // Led set as an output
  pinMode(led1Y, OUTPUT); // Led set as an output
  pinMode(led1G, OUTPUT); // Led set as an output
  pinMode(led2R, OUTPUT); // Led set as an output
  pinMode(led2Y, OUTPUT); // Led set as an output
  pinMode(led2G, OUTPUT); // Led set as an output
  pinMode(ledT, OUTPUT); // Led set as an output
  pinMode(pad, INPUT);  // input
  digitalWrite(led1G, LOW);
  digitalWrite(led1Y, LOW);
  digitalWrite(led1R, LOW);
  digitalWrite(led2G, LOW);
  digitalWrite(led2Y, LOW);
  digitalWrite(led2R, LOW);
  digitalWrite(ledT, LOW);
  }
void loop(){ 
   digitalWrite(led1G, HIGH);
   digitalWrite(led2R,HIGH);
  delay(15000); 
  digitalWrite(led1G, LOW);
  delay(1000);
  digitalWrite(led1Y, HIGH);
  delay(5000);
  digitalWrite(led1Y, LOW);
  delay(1000);
  digitalWrite(led1R, HIGH);
  if (pad = LOW); { 
  digitalWrite(ledT, HIGH);
  delay(5000);
  digitalWrite(ledT, LOW);
  }
   digitalWrite(led2R,LOW);
  digitalWrite(led2G,HIGH);
  delay(15000);
   digitalWrite(led2G,LOW);
   digitalWrite(led2Y,HIGH);
   delay(5000);
   digitalWrite(led2Y,LOW);
   digitalWrite(led1R, LOW);
}

Some ones assistance would be appreciated.
Dave

For comparising you must code a double equal-sign " == "

if (pad = LOW)
if (pad == LOW)

do you see the difference?

if (pad = LOW); { 

The semicolon is the only code executed conditionally when the if condition return true even when the single = is fixed. Delete it

If you Auto Format your sketch in the IDE the problem shows up clearly

if (pad == LOW)
    ;
{
    digitalWrite(ledT, HIGH);
    delay(5000);
    digitalWrite(ledT, LOW);
}

You don't digitalRead(pad)..
pad is the pin, (pad == LOW) will never evaluate true..

is there a pull up resistor in the pad pin??
maybe use pinMode(pad, INPUT_PULLUP); to use built in..

good luck.. ~q

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