Hello,
I see that up to 10 branches can be defined for the switch icon, is it possible to have more than 10 ?
or do I need to use 2 switchs icon ?
Thank you
Switch with more than 10 branches
Moderator: Benj
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Switch with more than 10 branches
Welcome to the forums...
Currently you would need to use two or more switch statements.
There are ways round - using a C block for example.
However, I would check if there isn't a better way to factor your code - and avoid large switch all together.
For example I've seen code of switch on arg 'Case 'A' - x = 1 Case 'B' - x = 2 Case 'C' x = 3 (up to Case 'Z'!) etc - which would be much better resolved using a calculation (in this case x = arg - 'A' + 1...)
Post us an example of what you are trying to achieve..
Martin
Currently you would need to use two or more switch statements.
There are ways round - using a C block for example.
However, I would check if there isn't a better way to factor your code - and avoid large switch all together.
For example I've seen code of switch on arg 'Case 'A' - x = 1 Case 'B' - x = 2 Case 'C' x = 3 (up to Case 'Z'!) etc - which would be much better resolved using a calculation (in this case x = arg - 'A' + 1...)
Post us an example of what you are trying to achieve..
Martin
Re: Switch with more than 10 branches
for example I might have 12 buttons, or 12 numeric display on the 2D Dashboard panel
and I have an array of 12 values
now I want to assign the 12 values of my array to the 12 numeric display
I don't think there is a way to "index" the numeric display from the handle name
so I might use a loop count to a variable with switch (variable)
and for each value 0/1/2/3/.../10/11 in the switch, I call the corresponding numeric display macro with the array[loop count variable] as parameter
and I have an array of 12 values
now I want to assign the 12 values of my array to the 12 numeric display
I don't think there is a way to "index" the numeric display from the handle name
so I might use a loop count to a variable with switch (variable)
and for each value 0/1/2/3/.../10/11 in the switch, I call the corresponding numeric display macro with the array[loop count variable] as parameter
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Switch with more than 10 branches
What about using the lookup table component?
That can derive a value from an index.
That can derive a value from an index.
Martin
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Switch with more than 10 branches
I think I see what you want to do:
In pseudocode:
x = ButtonPressed.id;
display[x] -> ShowSomething..
You would need to think how this would translate to hardware - for example how are the 'displays' connected. They could be selected by an address (i2c) or a CS/SS pin (SPI) and this value would be obtained from either a lookup table (or an array). If the 'displays' are just single LEDS - might be a PIN value or a position in array of WS2812 for example.
You might find that you run out of pins and or RAM quite quickly however - you would need to be careful (for example using SSD1306 64 x 128 displays - each would use 512 bytes RAM)
In an object orientated language - this would all be straightforward (an array of 'display' objects(really pointers to display objects)) - though on an MCU memory is usually at a premium and this probably isn't good unless on ARM or larger PIC. I believe v9 will have callbacks or you could use a little C to do this more elegantly than in FC at present. For example importing 12 x display will create 12 x each function used 12 x buffers / lookup tables where you really need a Display(dispNum, string/data) type routine or Select(display) then all display functions go to the currently selected display.
Martin
In pseudocode:
x = ButtonPressed.id;
display[x] -> ShowSomething..
You would need to think how this would translate to hardware - for example how are the 'displays' connected. They could be selected by an address (i2c) or a CS/SS pin (SPI) and this value would be obtained from either a lookup table (or an array). If the 'displays' are just single LEDS - might be a PIN value or a position in array of WS2812 for example.
You might find that you run out of pins and or RAM quite quickly however - you would need to be careful (for example using SSD1306 64 x 128 displays - each would use 512 bytes RAM)
In an object orientated language - this would all be straightforward (an array of 'display' objects(really pointers to display objects)) - though on an MCU memory is usually at a premium and this probably isn't good unless on ARM or larger PIC. I believe v9 will have callbacks or you could use a little C to do this more elegantly than in FC at present. For example importing 12 x display will create 12 x each function used 12 x buffers / lookup tables where you really need a Display(dispNum, string/data) type routine or Select(display) then all display functions go to the currently selected display.
Martin