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
Switch with more decisions
-
- Posts: 50
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 23, 2020 9:55 am
- Been thanked: 4 times
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Switch with more decisions
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
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
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: Switch with more decisions
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
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
-
- Posts: 50
- Joined: Wed Dec 23, 2020 9:55 am
- Been thanked: 4 times
Re: Switch with more decisions
Hello!
Workarounds are present. But it is easier programming with one variable for the decision. 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.
Workarounds are present. But it is easier programming with one variable for the decision. 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.
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: Switch with more decisions
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
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
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Switch with more decisions
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..
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..
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Switch with more decisions
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..
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..
-
- Posts: 50
- Joined: Wed Dec 23, 2020 9:55 am
- Been thanked: 4 times
Re: Switch with more decisions
Hi ,
I thought, that the numbers are fix in the switch. To change them was a good solution for me.
Thanks to all.
Jorg
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
Hi Martin
this looks quite interesting,
Thank you
this looks quite interesting,
could you please explain this with an example code, when you have free timemnfisher 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..
Thank you
S_V
-
- Matrix Staff
- Posts: 1465
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 204 times
- Been thanked: 347 times
Re: Switch with more decisions
Function pointers is an interesting option, but I don't think Flowcode would simulate this functionality.