Switch Case Example - 4 button remote with pushed and held


#1

I haven’t seen a ton of Switch examples on here while I was looking around on how to accomplish this particular task. So I figured that now that I have it done and working, that I would turn around and share it.

I have a 4 button remote where each button supports pushed and held. It’s the Aeon Minimote. I wanted to create a piston that could handle all 8 possible events that the remote can perform. I wanted it to be a simple, easy to understand design, and something that would be easy to work on. This is what I came up with, and it works great!

I created a switch statement that generates a string by combining the button id (index) as well as the action type (value) of either “pushed” or “held”.


#2

Thanks for your contribution… This looks like it could be quite useful…


With 8 triggers in play, an advanced version of testing might incorporate WAITs, and seeing if a different button interrupts or causes conflicts. (even though normally, I do not use WAITs in a multi-trigger piston)


#3

I already performed this test with logging messages under each case and everything worked as expected.

However, for the time being I don’t need any other cases filled for my uses, so I removed them.

As far as the race condition, I wasn’t too worried about testing that as I wasn’t planning on pressing a bunch of buttons on the remote rapidly, but I can look into that a bit.


#4

Excellent! Thanks for clarifying!