Page 1 of 2
Switch with more decisions
Posted: Tue Aug 13, 2024 8:25 am
by Jorg_Guldner
Hi,
the switch is actual for a maximum of 10 possibilities decisions written. For a project I need 12 decisions. If you change it, may be to do it for 16 decisions to have some on spare.
Jorg
Re: Switch with more decisions
Posted: Tue Aug 13, 2024 10:30 am
by mnfisher
There are other options.
1) Split over two (or more) switch statements.
2) Use a lookup table.
3) Use a calculation (if possible)
Give us some more details of your use case - and I'll try and provide an example.
Martin
Re: Switch with more decisions
Posted: Tue Aug 13, 2024 10:30 pm
by chipfryer27
Hi
As Martin suggests above, I use "switch" statements one after each other. First has options for up to 10, then the next 11 to 20.
Regards
Re: Switch with more decisions
Posted: Thu Aug 15, 2024 8:14 am
by Jorg_Guldner
Hello!
Workarounds are present. But it is easier programming with one variable for the decision.

- SWITCH with 12 decisions.jpg (49.96 KiB) Viewed 9860 times
You see one oled screen with 12 possibles inputs you can choose. There are other screens where you can choose 12 inputs again. The program must know, where you are actual standing on the screen. To split into 2 varables is more complecated.
Re: Switch with more decisions
Posted: Thu Aug 15, 2024 9:00 am
by stefan.erni
Hi Jorg
You can use the same variable in the switch.
You can also create 2 switch witch 6 position just choose the nummber.
it also has the advantage that the icon is not so wide
regards
Stefan
switch with 20 position

- 2024-08-15_09-51-36.PNG (70.84 KiB) Viewed 9856 times
Re: Switch with more decisions
Posted: Thu Aug 15, 2024 9:01 am
by mnfisher
switch(.x) 0..5 - first 6 options
switch(.x) 6..11 next 6 options
What happens for each option? For example if you set a variable to a value then a lookup table would be ideal.
For example say you set an led to a colour on each option then:
colour = lookup[.switch_value]
If things are more involved (for example some action) then create a macro for each action and use a lookup table of function pointers
In a C block;
FCV_LOOKUP[0] = FCM_Action0;
..
FCV_LOOKUP[11] = FCM_Action11;
Then use a line of C to run the action depending on a variable..
Re: Switch with more decisions
Posted: Thu Aug 15, 2024 9:01 am
by mnfisher
Stefan types fast!
It depends how many options you have - 12 would be fine in two switches. Lots - I'd look at other routes - very large macros make for unreadable (and unmaintainable) code..
Re: Switch with more decisions
Posted: Thu Aug 15, 2024 11:38 am
by Jorg_Guldner
Hi ,
I thought, that the numbers are fix in the switch. To change them was a good solution for me.
Thanks to all.
Jorg
Re: Switch with more decisions
Posted: Mon Sep 16, 2024 5:19 pm
by S_VE
Hi Martin
this looks quite interesting,
mnfisher wrote: ↑Thu Aug 15, 2024 9:01 am
If things are more involved (for example some action) then create a macro for each action and use a lookup table of function pointers
In a C block;
FCV_LOOKUP[0] = FCM_Action0;
..
FCV_LOOKUP[11] = FCM_Action11;
Then use a line of C to run the action depending on a variable..
could you please explain this with an example code, when you have free time
Thank you
Re: Switch with more decisions
Posted: Mon Sep 16, 2024 5:24 pm
by Steve-Matrix
Function pointers is an interesting option, but I don't think Flowcode would simulate this functionality.