Hi, i am new in arduino and i want your help. The thing is, i want to make traffic lights for EV preemtion. Traffic lights simulation for one direction just work fine. But when i give High signal(preemtion request) to input 9 or input 10 nothing happends. all i want to do is when 9 pin signal is high, green light should turn on for one direction while other direction turns red and vice versa. after that, traffic lights shouldn't stop and work in normal rhythm. I don't know how to control this and have watched many videos, but they are only about simple lights simulation. Please help Bellow is my code:
int green=2;
int yellow=3;
int red=4;
int value=9;
int i;
int n;
int value2=10;//
void setup() {
// put your setup code here, to run once:
pinMode(green,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(red,OUTPUT);
pinMode(value, INPUT);// if signal is high preemtion for one direction (from N to E)
pinMode(value2, INPUT);// if signal is high premtion for another direction (from S to N)
}
void loop() {
value = digitalRead(9);
if(value==HIGH){
turn_on_green();
}
// put your main code here, to run repeatedly:
//green
n=10;
for (i=0; i<n; i++)
{
delay(1000);
turn_on_green();
turn_on_green2();
digitalWrite(green,HIGH);
}
digitalWrite(green,LOW);
//yellow
n=5;
for (i=0; i<n; i++)
{
delay(1000);
turn_on_green();
turn_on_green2();
digitalWrite(yellow,HIGH);
}
digitalWrite(yellow,LOW);
//red
n=5;
for (i=0; i<n; i++)
{
delay(1000);
turn_on_green();
turn_on_green2();
digitalWrite(red,HIGH);
}
digitalWrite(red,LOW);
}
void turn_on_green()
{
if (digitalRead(value)==HIGH)
{
//green
n=10;
for (i=0; i<n; i++)
{
delay(1000);
digitalWrite(green,HIGH);
}
digitalWrite(green,LOW);
geltona
n=5;
for (i=0; i<n; i++)
{
delay(1000);
digitalWrite(yellow,HIGH);
}
digitalWrite(yellow,LOW);
//red
n=5;
for (i=0; i<n; i++)
{
delay(1000);
digitalWrite(red,HIGH);
}
digitalWrite(red,LOW);
}
}
void turn_on_green2()
{
if (digitalRead(value2)==HIGH)
{
//green
n=10;
for (i=0; i<n; i++)
{
delay(1000);
digitalWrite(green,HIGH);
}
digitalWrite(green,LOW);
//yellow
n=5;
for (i=0; i<n; i++)
{
delay(1000);
digitalWrite(yellow,HIGH);
}
digitalWrite(yellow,LOW);
//raudona
n=5;
for (i=0; i<n; i++)
{
delay(1000);
digitalWrite(red,HIGH);
}
digitalWrite(red,LOW);
}
}