Resolved/switch case looping?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
astro1234
Posts: 50
Joined: Mon Apr 10, 2017 12:53 pm
Has thanked: 39 times
Been thanked: 13 times
Contact:

Resolved/switch case looping?

Post by astro1234 »

Can some one please help me out with this file for flowcode v7. :?
What i am trying to do is for the loop to go through the switch case five
times then end, whats happening is the four leds light up when going
through the switch case then ending, with out going back to the loop again.
being trying varies ways but cannot sort this out.
thanks for looking.
regards astro1234
Attachments
Switch_Case.fcfx
(12.13 KiB) Downloaded 269 times
Last edited by astro1234 on Thu May 04, 2017 9:46 am, edited 1 time in total.

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: switch case looping?

Post by QMESAR »

Hi Try this
use the simulator in single step mode and you will see the loop execute 5 times
Attachments
Switch_Case.fcfx
(13.45 KiB) Downloaded 261 times

astro1234
Posts: 50
Joined: Mon Apr 10, 2017 12:53 pm
Has thanked: 39 times
Been thanked: 13 times
Contact:

Re: switch case looping?

Post by astro1234 »

QMESAR wrote:Hi Try this
use the simulator in single step mode and you will see the loop execute 5 times
Thank you QMESAR for helping me out with the problem, just two questions, what
is red circle by the left side of the calculation icon used for , and how can i let the file run
on its own with out using the step into icon.
Regards astro1234

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: switch case looping?

Post by Benj »

Hello Astro1234,
what is red circle by the left side of the calculation icon used for , and how can i let the file run on its own with out using the step into icon.
That is signifying a breakpoint. Simply right click the flowchart icon and from the menu you can switch off the breakpoint functionality.

https://www.matrixtsl.com/wikiv7/index. ... reakpoints

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: switch case looping?

Post by QMESAR »

You are welcome and Ben answered your questions Thanks Ben :D

astro1234
Posts: 50
Joined: Mon Apr 10, 2017 12:53 pm
Has thanked: 39 times
Been thanked: 13 times
Contact:

Re: switch case looping?

Post by astro1234 »

Benj wrote:Hello Astro1234,
what is red circle by the left side of the calculation icon used for , and how can i let the file run on its own with out using the step into icon.
That is signifying a breakpoint. Simply right click the flowchart icon and from the menu you can switch off the breakpoint functionality.

https://www.matrixtsl.com/wikiv7/index. ... reakpoints
Thanks QMESAR, i removed the breakpoint(i am learning :) ),but the loop does not stop at all,
the loop needs to run for five loops then stop, is your file ok ?.
i appreciate your help,thanks again.
Regards astro1234

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: switch case looping?

Post by medelec35 »

Hi astro1234
Do you mean like the attached Flowchart?

Martin
Attachments
Switch_Case V2.fcfx
(12.81 KiB) Downloaded 249 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: switch case looping?

Post by medelec35 »

Unless you want the program to totally end?
The above one restarted switch after 5th cycle
There is a much more efficient way to LED chase 5 times.
I can post that as well if you like?
Attachments
Switch_Case V3.fcfx
(12.66 KiB) Downloaded 253 times
Martin

astro1234
Posts: 50
Joined: Mon Apr 10, 2017 12:53 pm
Has thanked: 39 times
Been thanked: 13 times
Contact:

Re: switch case looping?

Post by astro1234 »

medelec35 wrote:Hi astro1234
Do you mean like the attached Flowchart?

Martin
Hello medelec35,
well its different, but its not what i am after,
if you put a led in a say a five loop routine, when the flowchart as completed the five loops
the flowchart ends. when you run your flowchart the loop neven ends, it just keeps on for ever.
what i am trying to do is, put a switch icon in a loop which runs five times then the flowchart ends
if that make sense.
thanks for looking at the flowchart.
Regards astro1234

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: switch case looping?

Post by medelec35 »

astro1234 wrote:what i am trying to do is, put a switch icon in a loop which runs five times then the flowchart ends
if that make sense
Yes,
The Flowchart is Switch_Case V3.fcfx which is one post above your latest reply.
At the time of writing has not been downloaded yet.
Switch_Case V2.fcfx was created in case you need to do something else fter the 5 loops.
Martin

astro1234
Posts: 50
Joined: Mon Apr 10, 2017 12:53 pm
Has thanked: 39 times
Been thanked: 13 times
Contact:

Re: switch case looping?

Post by astro1234 »

medelec35 wrote:
astro1234 wrote:what i am trying to do is, put a switch icon in a loop which runs five times then the flowchart ends
if that make sense
Yes,
The Flowchart is Switch_Case V3.fcfx which is one post above your latest reply.
At the time of writing has not been downloaded yet.
Switch_Case V2.fcfx was created in case you need to do something else fter the 5 loops.
Thank you medelec35/QMESAR/Benj.
Thats the flowchart routine what i was after,works great, thanks for your
help in getting it to work.
Regards astro1234

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: switch case looping?

Post by QMESAR »

HI
switch case five times then end,
I am sorry I missed the part that the loop should end after 5 times ,Thanks to the other guys picking it up also my Flowchart had no intentions of optimizing your Flowchart ,I wanted to point out that you can use for loop to loop a number of times :D
Happy you have it running now good luck :D

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: switch case looping?

Post by medelec35 »

Hi astro1234,
Glad it's working for you.
alternatively you don't need the loop variable.
You could just set loop count as 20

I have attached a more efficient way with less icons for educational interest.
I'm using bit manipulation:

Code: Select all

x = ((x << 1) & 15)

Code: Select all

<< 1
just shift bits left by 1 which is a more efficient way of multiplying by 2
& is bitwise AND; compares pairs of bits and returns 1 if both bits are 1, otherwise returns 0
In our case it determines the maximum number i.e. 15
So with

Code: Select all

((x << 1) & 15)
5 then if x starts off at 1, you should get:

Code: Select all

1
2
4
8
0
Since maximum number can never be more than 15
Attachments
Switch_Case V4.fcfx
(11.35 KiB) Downloaded 202 times
Martin

astro1234
Posts: 50
Joined: Mon Apr 10, 2017 12:53 pm
Has thanked: 39 times
Been thanked: 13 times
Contact:

Re: switch case looping?

Post by astro1234 »

medelec35 wrote:Hi astro1234,
Glad it's working for you.
alternatively you don't need the loop variable.
You could just set loop count as 20

I have attached a more efficient way with less icons for educational interest.
I'm using bit manipulation:

Code: Select all

x = ((x << 1) & 15)

Code: Select all

<< 1
just shift bits left by 1 which is a more efficient way of multiplying by 2
& is bitwise AND; compares pairs of bits and returns 1 if both bits are 1, otherwise returns 0
In our case it determines the maximum number i.e. 15
So with

Code: Select all

((x << 1) & 15)
5 then if x starts off at 1, you should get:

Code: Select all

1
2
4
8
0
Since maximum number can never be more that 15

Thank you medelec35 for your time in helping me out with this problem.(lot more questions to come to the forum regarding stepper drives, need to update my drive system for my telescope mount in the observatory ).

Now that flowchart i under stand, lot simpler than the other flowcharts.
Regards astro1234.

Post Reply