Main Site Documentation

Polling 20 button with a FEZ Cobra


#1

Hello GHI friends,

I need to poll 20 buttons to check if a button has been pressed.

Polling speed is important (need to detect at most 2 buttons pressed / second)

I plan to write an RLP looping routine to poll each button for a state change.

When a button’s state changes, I will exit the RLP loop, service the request, and then re-enter the RLP routine and continue polling.

I’d appreciate knowing if there is a better approach to detecting a state change in 20 buttons.

Thanks for the great products and excellent support!

Larry Scott
Walnut Creek, CA


#2

I would use as many interrupt ports as possible, then you don’t need to do polling.
Depending what else is connected to your cobra, there might be 20 interrupt capable pins.
Reacting within 0,5 sec, should not be a problem then, even without RLP.


#3

@ Larry1 -
I would consider a button matrix 4x5 so you can use 4 output and 5 input with a loop that can be done in .NET, I don’t think you will need RLP.


#4

I also think that a normal managed loop should be able to do it.
20 inputs in 500 ms means 25ms per button. That should be more than enough.
Just do all memory allocations in advance and store everything in static fields. By this GC does not interrupt you.


#5

Thanks guys, I appreciate the good feedback! I’ll get to work!


#6

dobova’s idea is the best solution. You can use 4 interrupt inputs and set the 5 outputs so that when a button is pressed, it generates an interrupt and then you simple do a scan to find the button.

Fast and efficient and no polling required.

This can also detect multiple presses at the same time.