Using Switch to choose a calculation output.

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

Moderator: Benj

Post Reply
User avatar
E*2Engineer
Posts: 35
Joined: Wed Dec 25, 2013 6:54 pm
Has thanked: 12 times
Been thanked: 6 times
Contact:

Using Switch to choose a calculation output.

Post by E*2Engineer »

Hello,
I am trying to display a LED on a every bit of every port sequentially.
To keep from having more than 1 led at a time on, I want to rule out all odd numbers.
Display 1 then 2, then 4, etc, on every port. The program is not complete i am aware, but I know that
nothing is going to work as I want the way it is.

Please look at the switch on the switch in macro "A". That is where I am not sure how to get the switch to choose 1 or 2
depending on an odd or even number.
If anyone can help me with this, I would appreciate it.

Program attached.
Thanks in advance.
Attachments
PROGRAMMING SOCKET TEST 1 10 17 0038.fcfx
Question is on macro A,
(25.02 KiB) Downloaded 251 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Using Switch to choose a calculation output.

Post by LeighM »

To test for odd or even, just AND with 1 ...
odd_even.jpg
odd_even.jpg (20.51 KiB) Viewed 5420 times

User avatar
E*2Engineer
Posts: 35
Joined: Wed Dec 25, 2013 6:54 pm
Has thanked: 12 times
Been thanked: 6 times
Contact:

Re: Using Switch to choose a calculation output.

Post by E*2Engineer »

Thank you for the reply,
But I just don't understand the A & 1 portion. Is there still a fmod in the program?
Or did you manage to remove that.
It seems you are treating 1 as a variable..........
Please send code with response.
Sorry, for the ignorance, I am new to what you are doing. NOT a Trump voter............ :lol:

User avatar
E*2Engineer
Posts: 35
Joined: Wed Dec 25, 2013 6:54 pm
Has thanked: 12 times
Been thanked: 6 times
Contact:

Explanation required on solution from LeighM

Post by E*2Engineer »

http://www.matrixtsl.com/mmforums/viewt ... 63&t=18457

The solution Leigh posted I did not really understand.

Could someone could give me some further help?

Please insert what he had in mind into my code attached, so I can single step through it and learn it.
Thank You.
Attachments
PROGRAMMING SOCKET TEST 1 10 17 1743.fcfx
(25.21 KiB) Downloaded 255 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Explanation required on solution from LeighM

Post by kersing »

Combining this message with your original question.

Code: Select all

A & 1
Means perform a bitwise AND operation on A with the number 1. The result of this operation is equal to zero (decision branch NO) if A is even and equal to 1 (decision branch YES) if A is odd. See wikipedia for an explanation on bitwise operators.
To use it in your program just input the code shown above in the condition of the decision icon.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
E*2Engineer
Posts: 35
Joined: Wed Dec 25, 2013 6:54 pm
Has thanked: 12 times
Been thanked: 6 times
Contact:

Re: Using Switch to choose a calculation output.

Post by E*2Engineer »

Thank You for that, got it working!

Post Reply