7 Buttons - one piston. Am I doing this right?


#1

1) Give a description of the problem
(I have a Mi magic cube. With the right DH this appears as 7 buttons. I want to create logic for all seven buttons. Memory utilization is about 24%. I would think it should be more efficient)

2) What is the expected behavior?
(Lower memory usage)

3) What is happening/not happening?
(Everything works as expected, unless buttons are “presses” to quickly in succession. I suspect this is due to too much overhead)

**4) Post a Green Snapshot

5) Attach any logs (From ST IDE and by turning logging level to Full)
(I will upload logs if needed.)

Thanks!


#2

You should wait for someone with more skills to answer but I would have used case switch (advanced statement) instead of elseif (1 trigger instead of 7) and you’ll probably need to set task cancellation policy to never.

Take that with a grain of salt tho, I write more in order to be corrected (again) and learn than to give you any kind of advice.


#3

what @Kebel871 said. only the first para :slight_smile:

EDIT: if you do switch to case structure, put in a break statement at the end of each case’s tasks.


#4

OK, next question: How do I specify in case statement button 1, 2 etc?
This is what I have so far as a test:


#5

tried ‘string’ already?


#6

I get tripped up on how to write the case statement. Case 1 should be button #1, case 2 should be button #2 and so on.
So Case Type = single value. But what do I use for “switch expression matches”?


#7

A similar question was asked recently about handling numeric keypad presses. This advice should apply to your device as well. Try a switch ($currentEventDeviceIndex) to handle events for each of the 7 buttons.


#8

see you have tried 1/2/… if thats not working try ‘1’/‘2’/… so on.


#16

Finally working! Based on advice from ipaterson. Thanks all for your help.

Below is the working piston in case it helps anybody else