This is my Whole code :
byte menu=2,ok=3,up=4,down=5,select=6;
int updown=0;
int menustate=0;
int lastmenustate=0;
int okstate=0;
int lastokstate=0;
int upstate=0;
int lastupstate=0;
int downstate=0;
int lastdownstate=0;
int upinstate=0;
int lastupinstate=0;
int downinstate=0;
int lastdowninstate=0;
int selectstate=0;
int lastselectstate=0;
bool da = false;
bool das = false;
int priority=0;
byte upp=19,downn=20;
int uppstate=0,lastuppstate=0,downnstate=0,lastdownnstate=0;
byte g1=7,r1=8,g2=9,r2=10,g3=11,r3=12,g4=13,r4=14,y1=15,y2=16,y3=17,y4=18;
unsigned long prev=0;
unsigned long inter[8]={4000,inter[0]/4,4000,inter[2]/4,4000,inter[4]/4,4000,inter[6]/4};
byte counter=0;
void traffic(byte a,byte b,byte c,byte d,byte e,byte f,byte g,byte h,byte k,byte l,byte m,byte n)
{
digitalWrite(r1,a);
digitalWrite(r2,b);
digitalWrite(r3,c);
digitalWrite(r4,d);
digitalWrite(g1,e);
digitalWrite(g2,f);
digitalWrite(g3,g);
digitalWrite(g4,h);
digitalWrite(y1,k);
digitalWrite(y2,l);
digitalWrite(y3,m);
digitalWrite(y4,n);
}
void select_priority()
{
selectstate=!digitalRead(select);
while(selectstate != lastselectstate)
{
real_time_exe();
uppstate=!digitalRead(up);
if(uppstate != lastuppstate)
{
priority++;
if(priority > 3)
priority = 0;
Serial.print("priority= ");
Serial.println(priority);
delay(100);
}
uppstate = lastuppstate;
downnstate =!digitalRead(down);
if(downnstate != lastdownnstate)
{
priority--;
if(priority < 0)
priority = 3;
Serial.print("priority= ");
Serial.println(priority);
delay(100);
}
downnstate = lastdownnstate;
if(!digitalRead(select))break;
delay(300);
}
selectstate = lastselectstate;
delay(100);
}
void real_time_exe()
{
select_priority();
if (priority ==0 )
{
switch(counter)
{
case 0:traffic(0,1,1,1,1,0,0,0,0,0,0,0);break;
case 1:traffic(0,1,1,1,0,0,0,0,1,0,0,0);break;
case 2:traffic(1,0,1,1,0,1,0,0,0,0,0,0);break;
case 3:traffic(1,0,1,1,0,0,0,0,0,1,0,0);break;
case 4:traffic(1,1,0,1,0,0,1,0,0,0,0,0);break;
case 5:traffic(1,1,0,1,0,0,0,0,0,0,1,0);break;
case 6:traffic(1,1,1,0,0,0,0,1,0,0,0,0);break;
case 7:traffic(1,1,1,0,0,0,0,0,0,0,0,1);break;
}
}
if (priority ==1 )
{
switch(counter)
{
case 0:traffic(0,1,1,1,1,0,0,0,0,0,0,0);break;
case 1:traffic(0,1,1,1,0,0,0,0,1,0,0,0);break;
case 2:traffic(1,1,1,0,0,0,0,1,0,0,0,0);break;
case 3:traffic(1,1,1,0,0,0,0,0,0,0,0,1);break;
case 4:traffic(1,1,0,1,0,0,1,0,0,0,0,0);break;
case 5:traffic(1,1,0,1,0,0,0,0,0,0,1,0);break;
case 6:traffic(1,0,1,1,0,1,0,0,0,0,0,0);break;
case 7:traffic(1,0,1,1,0,0,0,0,0,1,0,0);break;
}
}
if (priority ==2 )
{
switch(counter)
{
case 0:traffic(0,1,1,1,1,0,0,0,0,0,0,0);break;
case 1:traffic(0,1,1,1,0,0,0,0,1,0,0,0);break;
case 2:traffic(1,1,0,1,0,0,1,0,0,0,0,0);break;
case 3:traffic(1,1,0,1,0,0,0,0,0,0,1,0);break;
case 4:traffic(1,1,1,0,0,0,0,1,0,0,0,0);break;
case 5:traffic(1,1,1,0,0,0,0,0,0,0,0,1);break;
case 6:traffic(1,0,1,1,0,1,0,0,0,0,0,0);break;
case 7:traffic(1,0,1,1,0,0,0,0,0,1,0,0);break;
}
}
if (priority ==3 )
{
switch(counter)
{
case 0:traffic(0,1,1,1,1,0,0,0,0,0,0,0);break;
case 1:traffic(0,1,1,1,0,0,0,0,1,0,0,0);break;
case 2:traffic(1,1,1,0,0,0,0,1,0,0,0,0);break;
case 3:traffic(1,1,1,0,0,0,0,0,0,0,0,1);break;
case 4:traffic(1,0,1,1,0,1,0,0,0,0,0,0);break;
case 5:traffic(1,0,1,1,0,0,0,0,0,1,0,0);break;
case 6:traffic(1,1,0,1,0,0,1,0,0,0,0,0);break;
case 7:traffic(1,1,0,1,0,0,0,0,0,0,1,0);break;
}
}
if(millis()-prev>=inter[counter])
{
prev=millis();
counter++;
if(counter>7)
counter=0;
}
}
void setup()
{
for(int j=2;j<7;j++)
{
pinMode(j,INPUT_PULLUP);
}
for(int i=7;i<19;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
pinMode(upp,INPUT_PULLUP);
pinMode(downn,INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
real_time_exe();
menustate=!digitalRead(menu);
while(menustate != lastmenustate)//checking if the menu button is pressed
{
if(da == false)
{
Serial.print("Press Menu");
Serial.println("Light a");
Serial.println("Light b");
Serial.println("Light c");
Serial.println("Light d");
da=true;
}
upstate =!digitalRead(up);
if(upstate != lastupstate)//checking if the up button is pressed
{
updown++;
if(updown > 3)
updown=0;
Serial.print("updown= ");
Serial.println(updown);
delay(100);
}
upstate = lastupstate;
downstate =!digitalRead(down);
if(downstate != lastdownstate)
{
updown--;
if(updown < 0)
updown=3;
Serial.print("updown= ");
Serial.println(updown);
delay(100);
}
downstate = lastdownstate;
f();
g();
h();
k();
delay(300);
if(!digitalRead(menu))
break;
}
lastmenustate = menustate;
da=false;
delay(100);
}
void f()
{
real_time_exe();
okstate=!digitalRead(ok);
while((okstate != lastokstate) && (updown == 0))
{
//real_time_exe();
upinstate=!digitalRead(up);
if(upinstate != lastupinstate)
{
inter[0]+=1000;
if(inter[0] >= 90000)
inter[0] = 90000;
Serial.print("ainter= ");
Serial.println(inter[0]);
delay(100);
}
upinstate = lastupinstate;
downinstate =!digitalRead(down);
if(downinstate != lastdowninstate)
{
inter[0] = inter[0]-1000;
if(inter[0] >= 90000)
inter[0] = 0;
Serial.print("ainter= ");
Serial.println(inter[0]);
delay(100);
}
downinstate = lastdowninstate;
if(!digitalRead(menu))break;
}
okstate = lastokstate;
}
void g()
{
real_time_exe();
okstate=!digitalRead(ok);
while((okstate != lastokstate) && (updown == 1))
{
//real_time_exe();
upinstate=!digitalRead(up);
if(upinstate != lastupinstate)
{
inter[2]+=1000;
if(inter[2] >= 90000)
inter[2] = 90000;
Serial.print("binter= ");
Serial.println(inter[2]);
delay(100);
}
upinstate = lastupinstate;
downinstate =!digitalRead(down);
if(downinstate != lastdowninstate)
{
inter[2]-=1000;
if(inter[2] >= 90000)
inter[2] = 0;
Serial.print("binter= ");
Serial.println(inter[2]);
delay(100);
}
downinstate = lastdowninstate;
if(!digitalRead(menu))break;
}
okstate = lastokstate;
}
void h()
{
real_time_exe();
okstate=!digitalRead(ok);
while((okstate != lastokstate) && (updown == 2))
{
//real_time_exe();
upinstate=!digitalRead(up);
if(upinstate != lastupinstate)
{
inter[4]+=1000;
if(inter[4] >= 90000)
inter[4] = 90000;
Serial.print("cinter= ");
Serial.println(inter[4]);
delay(100);
}
upinstate = lastupinstate;
downinstate = !digitalRead(down);
if(downinstate != lastdowninstate)
{
inter[4]-=1000;
if(inter[4] >= 90000)
inter[4] = 0;
Serial.print("cinter= ");
Serial.println(inter[4]);
delay(100);
}
downinstate = lastdowninstate;
if(!digitalRead(menu))break;
}
okstate = lastokstate;
}
void k()
{
real_time_exe();
okstate=!digitalRead(ok);
while((okstate != lastokstate) && (updown == 3))
{
//real_time_exe();
upinstate=!digitalRead(up);
if(upinstate != lastupinstate)
{
inter[6]+=1000;
if(inter[6] >= 90000)
inter[6] = 90000;
Serial.print("dinter= ");
Serial.println(inter[6]);
delay(100);
}
upinstate = lastupinstate;
downinstate = !digitalRead(down);
if(downinstate != lastdowninstate)
{
inter[6]-=1000;
if(inter[6] >= 90000)
inter[6] = 0;
Serial.print("dinter= ");
Serial.println(inter[6]);
delay(100);
}
downinstate = lastdowninstate;
if(!digitalRead(menu))break;
}
okstate = lastokstate;
}
[code]
[/code]