Page 1 of 1

Using Switch to choose a calculation output.

Posted: Tue Jan 10, 2017 9:04 am
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.

Re: Using Switch to choose a calculation output.

Posted: Tue Jan 10, 2017 9:39 am
by LeighM
To test for odd or even, just AND with 1 ...
odd_even.jpg
odd_even.jpg (20.51 KiB) Viewed 6194 times

Re: Using Switch to choose a calculation output.

Posted: Tue Jan 10, 2017 8:02 pm
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:

Explanation required on solution from LeighM

Posted: Wed Jan 11, 2017 1:10 am
by E*2Engineer
http://www.flowcode.co.uk/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.

Re: Explanation required on solution from LeighM

Posted: Wed Jan 11, 2017 1:20 am
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.

Re: Using Switch to choose a calculation output.

Posted: Wed Jan 11, 2017 3:43 am
by E*2Engineer
Thank You for that, got it working!