Switch with more decisions

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
Jorg_Guldner
Posts: 50
http://meble-kuchenne.info.pl
Joined: Wed Dec 23, 2020 9:55 am
Been thanked: 4 times

Switch with more decisions

Post 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

mnfisher
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

Post 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

chipfryer27
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

Post 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

Jorg_Guldner
Posts: 50
Joined: Wed Dec 23, 2020 9:55 am
Been thanked: 4 times

Re: Switch with more decisions

Post by Jorg_Guldner »

Hello!
Workarounds are present. But it is easier programming with one variable for the decision.
SWITCH with 12 decisions.jpg
SWITCH with 12 decisions.jpg (49.96 KiB) Viewed 9862 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.

stefan.erni
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

Post 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
2024-08-15_09-51-36.PNG (70.84 KiB) Viewed 9858 times

mnfisher
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

Post 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..

mnfisher
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

Post 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..

Jorg_Guldner
Posts: 50
Joined: Wed Dec 23, 2020 9:55 am
Been thanked: 4 times

Re: Switch with more decisions

Post 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

S_VE
Posts: 26
Joined: Tue Jan 26, 2021 6:10 am
Has thanked: 32 times
Been thanked: 1 time

Flowcode v9 Re: Switch with more decisions

Post 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
S_V

Steve-Matrix
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

Post by Steve-Matrix »

Function pointers is an interesting option, but I don't think Flowcode would simulate this functionality.

Post Reply