Read simultaneous input from 10+ buttons

Hello.

I want working on a project and I'm stuck a little bit. Imagine that you are playing a game. 10 persons have one button each. And they press them after the command. The quickest get 10 points, second one 9 points etc. There are 10 rounds and I need to know who the winner is. So, the question is how can I read input from 10+ digital pins at once? I'm using Arduino Nano + i2c 16 input/output port expander + buttons and resistors (one resistor for each button).

The bad version is

a1=digitalRead(But1) a2=digitalRead(But2) ...

In this case, the first player will always have benefit and the last one - handicap. What should I do?

Hi,

Probably nothing. The Arduino will read all the buttons very quickly, and the first player will not see any benefit.

Paul

Ah yes!

Well, two things.

Firstly, you can read eight port inputs at a time by reading the whole port as a byte. You will need to read two ports successively for 10 (or more) individual inputs.

That bit is dead easy.

Now the tricky bit - the code loop that makes decisions according to what is read will take many times as long as it takes to read the ports. This means that if two inputs are pressed within the time it takes to make those decisions, they will appear to have been pressed simultaneously anyway even if one occurred immediately after the last read and the other immediately before the next read.

So the question is - how do you decide who is the winner if (and because the processor is operating extremely fast, this is only a matter of microseconds and absurdly improbable in the first place) two inputs are pressed simultaneously?