Stop a Light Traffic Sequence with Bluetooth Module

Hi Everyone, this is my project: I have a three light traffic sequence blinking one behind another and working with a bluetooth module, if I type '1' in the Bluetooth Mobile application, the sequence has to run normally, but, if a type '0', the sequence has to stop in the led that was blinking in the moment I typed '0' and let just that led On and the other two off.

I attach my code, Thanks.

long ld;
int state=0;

void setup()
{
pinMode (13,OUTPUT);
pinMode (11,OUTPUT);
pinMode (10,OUTPUT);
Serial.begin (9600);
}
void loop (){
if (Serial.available()){
state=Serial.parseInt();
if (state==1){

trafficlight(false);
state=1;
}
else
{
state=0;
trafficlight(true);

}
}else{
// state =0;
if(state ==0){

trafficlight(true);
state=0;
}
else{
trafficlight(false);
state=1;
}
}

}

void trafficlight(boolean v)
{
if (v)
{
state =0;
ld = random(1,4);
digitalWrite (10,HIGH);
delay(100);
digitalWrite (10,LOW);
delay (100);
digitalWrite (11,HIGH);
delay(500);
digitalWrite (11,LOW);
delay(500);
digitalWrite (13,HIGH);
delay(500);
digitalWrite (13,LOW);
//digitalWrite (10,HIGH);
//delay(1000);
}
else
{
if(ld==1){
digitalWrite (10,HIGH);
digitalWrite(10,LOW );
digitalWrite (11,LOW);

}
if(ld==2){
digitalWrite (10,LOW);
digitalWrite (11,HIGH);
digitalWrite(11,LOW);
}
if(ld==3){
digitalWrite (10,LOW);
digitalWrite (11,LOW);
digitalWrite (13,HIGH);
digitalWrite(13,LOW);
}

}
}``

TrafficLight.ino (1.14 KB)

I attach my code

Why didn't you simply post it?

sorry, ít's already done

I wonder why no-one ever seems to read the posting guidelines? {sigh}