Ahhh now I know what a Priority encoder is :) I have a similar thing in the vX, if adapted to your needs you could use a bitfield and then hold the button states within it, then bitshift it left and count how many shifts until the carry bit is set, or use a for... loop and test each bit from highest to lowest. The counter is then subtracted from the total number of bits and that will tell you the number of the highest set bit. In your case you could optimise this for speed at the expense of code space and ram by holding the current highest button in a variable. When a button is set, compare that button number to see if it is higher that the current highest button, and then setting the current button to be the highest. When a button is unset, if it is the highest number, you could start reading all the lower pin numbers than that, with the method described above, and if the button is lower it is ignored. . I'd be interested to see if the hardware method in the link above could be easily adapted to software but I'll leave that up to you :) Hope that helps! Edit: There may be much better ways to do this, as it's a very common requirement it wouldn't surprise me if there's a standardised method... Hopefully my method isn't too clumsy!