3

What I see is just a simple if/then/else. What I am looking for is to be able to add multiple options, more than yes/no.

I use a motor as a switcher, so I rotate it to some position and measure its degrees to switch the mode of the robot and there are going to be more than 2 modes, like 4-8. How can I do it in an elegant way?

4

I just discovered this a few days ago. If you use "Numeric" as the input type and switch to tabbed view, you can have a select/case/default type instruction instead of if/then. It also works with text input as well as as some sensors.

enter image description here

enter image description here

2

I would suggest stacking your switch statements by placing switch statements into one another like in the below image. Make sure your conditions overlap, so you are only testing for values in A1 and A2 that are WITHIN your A condition, same for B.

Switches in a switch

1

Yes, multiple switch statements can be nested inside each other.

However, given the problem of a measuring a motor's rotation and converting that into a user choice doing the math first and using that result in a single switch statement is possible.

Also, the logic will need to run more than once and give the user some indication of the current selection. That much, might look like this:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.