library ieee; use ieee.std_logic_1164.all; entity Blinky is port ( Clock : in std_logic; Reset : in std_logic; TimerEvent1 : in std_logic; TimerEvent2 : in std_logic; GoLeft : in std_logic; GoRight : in std_logic; Invert : in std_logic; Speed : in std_logic; Leds : out std_logic_vector(7 downto 0)); end Blinky; architecture behavior of Blinky is type mode is (GoingRight, GoingLeft); signal current_mode : mode; signal next_mode : mode; signal current_light : integer range 0 to 7; signal next_light : integer range 0 to 7; signal TheTimer_Event : std_logic; signal Pattern : std_logic_vector(7 downto 0); begin MakeRegisters : process (Clock, Reset) begin if Reset = '1' then current_light <= 7; current_mode <= GoingRight; elsif Clock'event and Clock = '1' then current_light <= next_light; current_mode <= next_mode; end if; end process MakeRegisters; TheTimer_Event <= TimerEvent1 when Speed = '0' else TimerEvent2; MakeNext : process (GoLeft, GoRight, TheTimer_Event, current_light, current_mode) begin next_light <= current_light; next_mode <= current_mode; if GoLeft = '1' then next_mode <= GoingLeft; elsif GoRight = '1' then next_mode <= GoingRight; end if; if TheTimer_Event = '1' then if current_mode = GoingRight then if current_light = 0 then next_light <= 7; else next_light <= current_light - 1; end if; elsif current_mode = GoingLeft then if current_light = 7 then next_light <= 0; else next_light <= current_light + 1; end if; end if; end if; end process MakeNext; decoder : process (current_light) begin for i in 0 to 7 loop if i = current_light then Pattern(i) <= '1'; else Pattern(i) <= '0'; end if; end loop; end process decoder; Leds <= Pattern when Invert = '0' else not Pattern; end behavior;