Introduction
I’ve noticed folks asking about being able to include an “AND” statement/comparison/functionality for their advanced Apex Fusion programming but haven’t seen a lot of information on the subject. I put my electrical engineering hat on and thought long and hard about this problem. Not only did I figure out how to include AND functionality, but also OR, NAND (the opposite output of AND), NOR, (the opposite output of “OR”). You do need to use Virtual Outputs to use these comparisons.
How To:
The following are the concepts to understand the below information:
Logic States
0 = OPEN or OFF
1 = CLOSED or ON
The 0’s and 1’s below can represent the state of an apex switch input, outlet, or virtual output. I will first show the logic for the comparison and then the corresponding Apex code.
For simplicity, the Apex code below represents a virtual output comparing switch inputs.
AND Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 0
1 + 0 = 0
0 + 1 = 0
1 + 1 = 1
Set ON
If SW1 = OPEN Then OFF
If SW2 = OPEN Then OFF
OR Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 1
Set OFF
If SW1 = CLOSED Then ON
If SW2 = CLOSED Then ON
NAND Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 1
1 + 0 = 1
0 + 1 = 1
1 + 1 = 0
Set OFF
If SW1 = OPEN Then ON
If SW2 = OPEN Then ON
NOR Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 1
1 + 0 = 0
0 + 1 = 0
1 + 1 = 0
Set ON
If SW1 = CLOSED Then OFF
If SW2 = CLOSED Then OFF
More than 2 Comparisons
You can expand the comparisons to 3 or more items too. For instance, below is the logic and code for an 3 input AND comparison.
Logic
Input 1 + Input 2 + Input 3 = Virtual Output
0 + 0 + 0 = 0
1 + 0 + 0 = 0
0 + 1 + 0 = 0
1 + 1 + 0 = 0
0 + 0 + 1 = 0
1 + 0 + 1 = 0
0 + 1 + 1 = 0
1 + 1 + 1 = 1
Set ON
If SW1 = OPEN Then OFF
If SW2 = OPEN Then OFF
If SW3 = OPEN Then OFF
BONUS – VERY Advanced Programming (XOR)
XOR logic is a comparison state that turns ON the output if the inputs do not match. Otherwise, the output is OFF. This is a bit complicated and will take good organized/planned-out coding.
XOR Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 0
First create a virtual output (let’s call it voNAND) and use a NAND comparison on Input 1 + Input 2.
Then create a 2nd virtual output (let’s call in voOR) and use an OR comparison on Input 1 + Input 2.
Finally create a 3rd virtual output (voANDFinalOutput) and use an AND comparison on voNAND + voNOR.
If you follow the logic, this is how you get the XOR output.
NAND + OR = AND
1 + 0 = 0
1 + 1 = 1
1 + 1 = 1
0 + 1 = 0
Conclusion
My hope is this knowledge advances our hobby and gives us better control over our systems.
In the next few days, I will post how I use this type of programming to get 7 manual functions (i.e. turn on my LEDs to 5%, turn off the skimmer, etc…) using only 3 Apex switch inputs.
#apexusers
I’ve noticed folks asking about being able to include an “AND” statement/comparison/functionality for their advanced Apex Fusion programming but haven’t seen a lot of information on the subject. I put my electrical engineering hat on and thought long and hard about this problem. Not only did I figure out how to include AND functionality, but also OR, NAND (the opposite output of AND), NOR, (the opposite output of “OR”). You do need to use Virtual Outputs to use these comparisons.
How To:
The following are the concepts to understand the below information:
Logic States
0 = OPEN or OFF
1 = CLOSED or ON
The 0’s and 1’s below can represent the state of an apex switch input, outlet, or virtual output. I will first show the logic for the comparison and then the corresponding Apex code.
For simplicity, the Apex code below represents a virtual output comparing switch inputs.
AND Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 0
1 + 0 = 0
0 + 1 = 0
1 + 1 = 1
Set ON
If SW1 = OPEN Then OFF
If SW2 = OPEN Then OFF
OR Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 1
Set OFF
If SW1 = CLOSED Then ON
If SW2 = CLOSED Then ON
NAND Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 1
1 + 0 = 1
0 + 1 = 1
1 + 1 = 0
Set OFF
If SW1 = OPEN Then ON
If SW2 = OPEN Then ON
NOR Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 1
1 + 0 = 0
0 + 1 = 0
1 + 1 = 0
Set ON
If SW1 = CLOSED Then OFF
If SW2 = CLOSED Then OFF
More than 2 Comparisons
You can expand the comparisons to 3 or more items too. For instance, below is the logic and code for an 3 input AND comparison.
Logic
Input 1 + Input 2 + Input 3 = Virtual Output
0 + 0 + 0 = 0
1 + 0 + 0 = 0
0 + 1 + 0 = 0
1 + 1 + 0 = 0
0 + 0 + 1 = 0
1 + 0 + 1 = 0
0 + 1 + 1 = 0
1 + 1 + 1 = 1
Set ON
If SW1 = OPEN Then OFF
If SW2 = OPEN Then OFF
If SW3 = OPEN Then OFF
BONUS – VERY Advanced Programming (XOR)
XOR logic is a comparison state that turns ON the output if the inputs do not match. Otherwise, the output is OFF. This is a bit complicated and will take good organized/planned-out coding.
XOR Logic
Input 1 + Input 2 = Virtual Output
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 0
First create a virtual output (let’s call it voNAND) and use a NAND comparison on Input 1 + Input 2.
Then create a 2nd virtual output (let’s call in voOR) and use an OR comparison on Input 1 + Input 2.
Finally create a 3rd virtual output (voANDFinalOutput) and use an AND comparison on voNAND + voNOR.
If you follow the logic, this is how you get the XOR output.
NAND + OR = AND
1 + 0 = 0
1 + 1 = 1
1 + 1 = 1
0 + 1 = 0
Conclusion
My hope is this knowledge advances our hobby and gives us better control over our systems.
In the next few days, I will post how I use this type of programming to get 7 manual functions (i.e. turn on my LEDs to 5%, turn off the skimmer, etc…) using only 3 Apex switch inputs.
#apexusers
Last edited: