library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity light is
port(clk,clr,set_red:in std_logic;
a_green,a_yellow,a_red:out std_logic;
b_green,b_yellow,b_red:out std_logic);
end light;
architecture rtl of light is
type state is(agreen,ayellow,bgreen,byellow,alarm);
--begin
signal current_state,next_state:state;
signal timer:integer;
signal light:std_logic_vector(5 downto 0);
signal flag:std_logic;
begin
process(clk,clr,set_red)
begin
if(clr='1')then
current_state <= agreen;
--timer <= 50;
flag <='0';
--elsif(set_red='1')then
--current_state <= alarm;
--timer <=timer;
--flag <='1';
--light <="001001" ;
elsif(clk'event and clk='1')then
flag <='0';
--timer <=timer-1;
--if(timer=timer-1)
current_state <= next_state;
end if;
end process;
process(current_state,set_red)
begin
case current_state is
when agreen=>
if(timer=0)then
next_state <=ayellow;
timer <=5;
end if;
when ayellow =>
if(timer=0)then
next_state <=bgreen;
timer <=50;
end if;
when bgreen=>
if(timer=0)then
next_state <=byellow;
timer <=5;
end if;
when byellow=>
if(timer=0)then
next_state <=agreen;
timer <=50;
end if;
when alarm=>
if(timer=0)then
next_state <=alarm;
end if;
end case;
end process;
process(current_state)
--if(flag='0')then
begin
case current_state is
when agreen => light <="100001";
when ayellow => light <="010001";
when bgreen => light <="001100";
when byellow => light <="001010";
when alarm => light <="001001";
end case;
--end if;
a_green <=light(5);
a_yellow <=light(4);
a_red <=light(3);
b_green <=light(2);
b_yellow <=light(1);
b_red <=light(0);
end process;
end rtl;