Hii.....
I am working on density based traffic light control system and I wish that I get the density acknowledgement by using interrupt 0and 1 both, I want that whenever the interrupt 0 occurs the delay should be increased to say 5 secs and whenever the interrupt 1 occurs the same delay should be increased by 3 more secs. Please help me to get this done. here is the code on which I am working.
int G1G3 = A0;
int R1R3 = A1;
int G2G4 = A2;
int R2R4 = A3;
int Y1Y3 = A4;
int Y2Y4 = A5;
void setup()
{
Serial.begin(9600);
pinMode(G1G3,OUTPUT);
pinMode(R1R3,OUTPUT);
pinMode(G2G4,OUTPUT);
pinMode(R2R4,OUTPUT);
pinMode(Y1Y3,OUTPUT);
pinMode(Y2Y4,OUTPUT);
//first make all the lanes red for purpose of demo
digitalWrite(R1R3,HIGH);
digitalWrite(R2R4,HIGH);
delay(3000);
attachInterrupt(0,dense1,RISING);
attachInterrupt(1,dense2,RISING);
}
void loop()
{
//start with lane 1 and 3
digitalWrite(R1R3,LOW);
digitalWrite(G1G3,HIGH);
delay(3000); ///this delay is supposed to change when interrupt occurs
digitalWrite(G1G3,LOW);
digitalWrite(Y1Y3,HIGH);
delay(500);
digitalWrite(Y1Y3,LOW);
digitalWrite(R1R3,HIGH);
//DEMO of lane ! and # ends here
//start lane 2 and 4
digitalWrite(R2R4,LOW);
digitalWrite(G2G4,HIGH);
delay(3000);
digitalWrite(G2G4,LOW);
digitalWrite(Y2Y4,HIGH);
delay(500);
digitalWrite(Y2Y4,LOW);
digitalWrite(R2R4,HIGH);
//DEMO of lane 2 and 4 ends here
}
void dense1()
{
//start with lane 1 and 3
digitalWrite(R1R3,LOW);
digitalWrite(G1G3,HIGH);
delay(3000); ///the delay which is supposed to change on occurance of interrupt
digitalWrite(G1G3,LOW);
digitalWrite(Y1Y3,HIGH);
delay(500);
digitalWrite(Y1Y3,LOW);
digitalWrite(R1R3,HIGH);
//DEMO of lane ! and # ends here
//start lane 2 and 4
digitalWrite(R2R4,LOW);
digitalWrite(G2G4,HIGH);
delay(3000);
digitalWrite(G2G4,LOW);
digitalWrite(Y2Y4,HIGH);
delay(500);
digitalWrite(Y2Y4,LOW);
digitalWrite(R2R4,HIGH);
//DEMO of lane 2 and 4 ends here
}