title: VHDL Traffic Light Controller
body: <p>Here is a simple code for a traffic light controller. It cycles through the states according to the counter values. However I would like it stay an additional 10 seconds on the first state when a pushbutton is pressed any ideas how I would do that.</p>
  
  <pre><code>library IEEE;
  use IEEE.STD_LOGIC_1164.ALL;
  use ieee.std_logic_unsigned.all;
  
  entity TLC is
      Port (
                Trafficlights: out  STD_LOGIC_Vector (5 downto 0);
                Clck : in  STD_LOGIC;
                Reset : in  STD_LOGIC;
                P_B : in STD_LOGIC);
   end TLC;
  
  architecture Behavioral of TLC is
    type state_type is (st0_R1_G2, st1_R1_A1_A2, st2_G1_R2, st3_A1_R2_A2); 
  
    signal state: state_type; 
    signal count : std_logic_vector (3 downto 0);
  
    constant sec10 : std_logic_vector ( 3 downto 0) := "1010";
    constant sec2 : std_logic_vector (3 downto 0 ) := "0010";
    constant sec16: std_logic_vector (3 downto 0 ) := "1111";
  begin
    process (Clck,Reset)
    begin
      if Reset='1' then
        state &lt;= st0_R1_G2;         --reset to initial state
        count &lt;= X"0";             -- reset counter
      elsif Clck' event and Clck = '1' then --rising edge
         case (state) is              ---state transitions
           when st0_R1_G2 =&gt;
             if count &lt; sec10 then
               state &lt;= st0_R1_G2;
               count &lt;= count + 1;                
             else  
               state &lt;= st1_R1_A1_A2;
               count &lt;= X"0";
             end if;
  
           when st1_R1_A1_A2 =&gt;
             if count &lt; sec2 then
               state &lt;=  st1_R1_A1_A2;
               count &lt;= count + 1;
             else
               state &lt;= st2_G1_R2;
               count &lt;= X"0";
             end if;
  
           when st2_G1_R2 =&gt;
             if count &lt; sec10 then
               state &lt;= st2_G1_R2;
               count &lt;= count + 1;
             else
               state &lt;= st3_A1_R2_A2;
               count &lt;= X"0";
             end if;
  
           when st3_A1_R2_A2 =&gt;   
             if count &lt; sec2 then
               state &lt;=  st3_A1_R2_A2;
               count &lt;= count + 1;
             else
               state &lt;=st0_R1_G2;
               count &lt;= X"0";
             end if; 
  
           when others =&gt;
             state &lt;= st0_R1_G2;
         end case;      
       end if;
     end process;
  
     OUTPUT_DECODE: process (state)
     begin
       case state is 
         when st0_R1_G2 =&gt;    Trafficlights &lt;= "100001";  -- Traffic Red 1, Pedestrian Green 1 
         when st1_R1_A1_A2 =&gt; Trafficlights &lt;= "110010";
         when st2_G1_R2 =&gt;    Trafficlights &lt;= "001100";
         when st3_A1_R2_A2 =&gt; Trafficlights &lt;= "010110";
         when others =&gt;       Trafficlights &lt;= "100001";
       end case; 
     end process;
   end Behavioral;
  </code></pre>