NEWBIE NEED HELP ABOUT MY CODE

Hi to all the member of this forum, i am newbie about writing code.

here is my project...

i have 3 LED hook up on pin13,pin12,pin11 and button hook up on pin2, here i would like to do, when i push the button LED Pin13 will light-up and will turn off after 1000ms, after that LED Pin12 will light-up and turn off after 500ms, after that the LED Pin11 will light-up and stay on as long as the button is push, if the push button is no longer push the LED Pin11 is off, (in short there is no LED is ON)

please help me to fix this code of mine...

Thanks and advance...

int switchPin = 2;
int ledDelay = 1000;
int redPin = 13;
int yellowPin = 12;
int greenPin = 11;

void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
}

void loop()
{
  if(digitalRead(switchPin) == HIGH)
  {
    digitalWrite(redPin, HIGH);
    delay(ledDelay);
    digitalWrite(redPin, LOW);
    digitalWrite(yellowPin, HIGH);
    delay(500);
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
  
  }
  else
  {
    digitalWrite(greenPin, LOW);
  }
}

You seem to set redpin low twice, I think you want to change that to yellowpin :)

Why not simplify it to:

while(digitalRead(switchPin)==LOW); // Wait for button to be pressed

// Flash red LED
digitalWrite(redPin,HIGH);
delay(1000);
digitalWrite(redPin, LOW);

// Flash yellow LED
digitalWrite(yellowPin, HIGH);
delay(500);
digitalWrite(yellowPin, LOW);

// Turn on green LED until button released
digitalWrite(greenPin, HIGH);
while(digitalRead(switchPin)==HIGH);  // Wait for button to be released
digitalWrite(greenPin,LOW);

thegeekway: You seem to set redpin low twice, I think you want to change that to yellowpin :)

hi, i just change it the redpin to yellowpin but there is no changes happen, it is still the redpin and yellowpin on and off all over. i need to turn off the redpin and yellow pin if the greenpin is on...

thanks

majenko: Why not simplify it to:

while(digitalRead(switchPin)==LOW); // Wait for button to be pressed

// Flash red LED digitalWrite(redPin,HIGH); delay(1000); digitalWrite(redPin, LOW);

// Flash yellow LED digitalWrite(yellowPin, HIGH); delay(500); digitalWrite(yellowPin, LOW);

// Turn on green LED until button released digitalWrite(greenPin, HIGH); while(digitalRead(switchPin)==HIGH);  // Wait for button to be released digitalWrite(greenPin,LOW);

i am trying your code but i there is an error in (here is what i read in screen.. expected unqualified-id before while)

You need to post your code. All of it.

majenko: Why not simplify it to:

while(digitalRead(switchPin)==LOW); // Wait for button to be pressed

// Flash red LED digitalWrite(redPin,HIGH); delay(1000); digitalWrite(redPin, LOW);

// Flash yellow LED digitalWrite(yellowPin, HIGH); delay(500); digitalWrite(yellowPin, LOW);

// Turn on green LED until button released digitalWrite(greenPin, HIGH); while(digitalRead(switchPin)==HIGH);  // Wait for button to be released digitalWrite(greenPin,LOW);

i just done it and its works...... thanks a lot your an angel to me..... :)

AWOL: You need to post your code. All of it.

Thanks for making a post this forum help me a lot maybe in future i am the one to give a helping hand to newbie..

thanks to all...... :)