title: VHDL - how to detect and output correct priority
body: <p>Currently, I am working on a parking lot system in VHDL.</p>
  
  <p>The goal is simple. When a car parks, it will take a look at all the available spots and output the next empty spot. Seem simple enough, but I am having some problems getting it to work properly.</p>
  
  <p>I am using switches on a board and detecting when the switches are up. That signifies weather there is a car parked there or not. </p>
  
  <p>The goal is that I can hit for example, switch 1, switch 2 and switch 4 and till output 3 as the available spot. Then, if I switch on 3, it'll recalculate and say 5 is the next available spot.</p>
  
  <p>To accomplish this, I am using a bunch of if else statements, but whats happening is that the for example, if I hit the #4 switch, it'll properly display 5, but then once i hit the #5 switch, it will continue to show 5 as the next available spot rather than 6.</p>
  
  <p>I think my problem is that I don't have enough conditions to cover all scenarios. Is there a way for me to write this in a shorter way?</p>
  
  <pre><code>library IEEE;
  use IEEE.STD_LOGIC_1164.ALL;
  use IEEE.STD_LOGIC_ARITH.ALL;
  use IEEE.STD_LOGIC_UNSIGNED.ALL;
  
  entity Priority is
  port(
      SWITCH: in std_logic_vector (8 downto 0);
      H1: out std_logic_vector (3 downto 0);
      H2: out std_logic_vector (3 downto 0);
      H3: out std_logic_vector (3 downto 0);
      H4: out std_logic_vector (3 downto 0)
  );
  end Priority;
  
  architecture Behavioral of Priority is
  
  begin 
  process (SWITCH)
  begin
  
  if (SWITCH(0) = '1' AND SWITCH(1) = '1' AND SWITCH(2) = '1' AND SWITCH(3) = '1' AND SWITCH(4) = '1' AND SWITCH(5) = '1' AND SWITCH(6) = '1' AND SWITCH(7) = '1')   then  --if all switches are on, display "FULL"
  
  
  H1 &lt;= "1100";
  H2 &lt;= "1100";
  H3 &lt;= "1011";
  H4 &lt;= "1010";
  
  
  elsif SWITCH(0) = '1' then  --if switch 0 is turned on, show "PS-1"
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "0010";
  
  
  
  elsif SWITCH(1) = '1' then  --if switch 1 is turned on, show "PS-2"
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "0011";
  
  
  
  elsif SWITCH(2) = '1' then  
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "0100";
  
  
  
  elsif SWITCH(3) = '1' then  
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "0101";
  
  
  
  elsif SWITCH(4) = '1' then  
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "0110";
  
  
  
  elsif SWITCH(5) = '1' then  
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "0111";
  
  
  elsif SWITCH(6) = '1' then  
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "1000";
  
  
  
  elsif SWITCH(7) = '1' then  
  
  H1 &lt;= "1101";
  H2 &lt;= "1110";
  H3 &lt;= "1111";
  H4 &lt;= "0001";
  
  
  end if;
  --end if;
  
  end process;
  
  end Behavioral;
  </code></pre>