# Thread: Beginning of an Automatic Climate Control System, all juiced up on Fusion

1. So you want a function with a bunch of variables in (1 per bit) and outputs a number that the true/false binary variable inputs will represent right?

This is easy since you have a known number of bits. If you dont make true/false bits, but rather 1/0 bits, then all you need is bitA*2^bit# + bitB*2^bit# + bitC*2^bit# and so on.

2. Originally Posted by 2k1Toaster
So you want a function with a bunch of variables in (1 per bit) and outputs a number that the true/false binary variable inputs will represent right?

This is easy since you have a known number of bits. If you dont make true/false bits, but rather 1/0 bits, then all you need is bitA*2^bit# + bitB*2^bit# + bitC*2^bit# and so on.
I'm a little confused.

I get what you're saying about the usefulness of 1/0 bits for the math, but the math looks like DAC math.

where 1010 = 1*2^3+0*2^2+1*2^1+0*2^0 = 10.

I need ADC math. I have a variable that, for all purposes, is an analog value, that I need to convert to binary, to drive a DAC.

Right now I'm working on
MSB------ If X is >=2^5, then MSBvariable=1, else 0
MSB-1----If (X - MSBvariable*2^5) >= 2^4, then MSB-1variable=1, else 0
MSB-2----and so on
MSB-3----
MSB-4----
LSB-------

But this takes into account intermediately derrived variables, and is heavily sequence dependant...might be buggy.

3. ah sorry, yes I was going the other way.

I am working on a switch like this:

Code:
```      <switch object_type="variable" object_id="variable_test">
<case parameter1="19" parameter2="20" check="between">
<variable do="set" name="variable_test">
<parameter1>
<variable do="get" name="variable_test"></variable>
</parameter1>
<parameter2>
<number>1</number>
</parameter2>
</operation>
</variable>
</case>
<case parameter1="20" parameter2="22.9" check="between">
<variable do="set" name="variable_test">
<parameter1>
<variable do="get" name="variable_test"></variable>
</parameter1>
<parameter2>
<number>2</number>
</parameter2>
</operation>
</variable>
</case>
<case parameter1="23" check="greater than or equal to">
<variable do="set" name="variable_test">
<operation type="subtract">
<parameter1>
<variable do="get" name="variable_test"></variable>
</parameter1>
<parameter2>
<number>2</number>
</parameter2>
</operation>
</variable>
</case>
</switch>```
That should simplify things once I get it implemented.

4. I like where you're going there, oddly enough it makes sense (getting over my code phobias here). It also opened my eyes a little to the prospects and power of using <variable do="set" name=""> as opposed to then statements, for condensing/simplifying things.

5. If the functionality shown with the red edits I made (at least the top ones)were allowable, I could do it all in one function!!!

I think..

6. But really, this method knocks it down to 6 functions max. By putting the set_var at the output of the >=, and then just make another loop for the next most significant bit cascaded further as shown with the further-down >= having the set_var for the next most significant bit,...

Eliminates the need for ELSE!!!!

Any flaws?

7. I can't find a very direct way to tie a digital output to a variable's state (1 or 0), I think what I was thinking about earlier had more to do with buttons.

6 more functions maybe,... I'll need to use a 'then' statement on the initial 6 functions to say if true = ouput -on and then another to look at the var_temp_MSB variable and add a then statement to turn the variable off if the initial function evaluated false (variable will be 0).

getting there.

8. Ahhh...for the want of a case statement.

9. I was hoping that mathmatical operators in functions would treat a true/false input as 1/0 but it's not looking like it.

I'll try to be clear on this, because I'm stuck and I don't think there's a way around it.

If I have a variable that I want use as 1/0 logic (Numeric, but used as boolean). And I place a "set" reference for that variable in a Root Function at the ouput of a compare block (>=), according to the variable window (debug) the variable becomes True/False depending on the (>=) condition.

This would be fine with me, but, I use that variable as a multiplier in another loop. And appearantly 'True' * 32 != 32. Same is true for utilizing the state of an output in a loop. 'On' * 16 != 16.

Then the final roadblock for me is using a second 'then' statement to assign a value to a variable (obvious work-around for the above situation).

I have a second "Then" statement that assigns this variable a 1 if loop#1 is true, and a 0 if loop#2 is true.

Looking at my variable debug window, this isn't working properly.

!!!EDIT!!! I left FCC running with the variable debug window up for an unknown time period (greater than 10 minutes) and that variable finally did change to a 1 from a 0, as it should have, but I don't know when. I only know that it wasn't right away (should have been). I haven't been able to reproduce this in less than 20 minutes running at a time.!!!EDIT!!!

I tried using different values for the opinion: 1, 0, +1, +0, and "0" (the last of which gave me a parse error saying to contact you).

I know d+1, and d-1 worked with my test buttons, but incrementing will get me in to troubles pretty fast with this, so I didn't even try it.

2K1Toaster,
If you need me to clarify the problem(s), even a little, don't hesitate to say so, I'd like to make it as easy as possible to find... so that you can help me

And finally, when closing FCC with the red X, it seems like 65%-80% of the time, it hangs, and needs to be forcibly closed (but runs well prior to that).

10. the configurator is rejecting all of my 'Reset' loops or "else' loops, forcing me to continue in code only. It says: Function is unreadable. Must have a second tier node of "boolean_operation" or "operation". I'm using a NOT for that node. So appearantly that's not acceptable.

Here's 4 root functions I have for the MSB and MSB-1:

Code:
```      <if fire_on="logic" minimum_delta_vote_time="100" id="Root Function TempMSB_Set">
<boolean_operation type="greater than or equal to">
<parameter1>
<variable do="get" name="variable_Temp_Control_63"></variable>
</parameter1>
<parameter2>
<number>32</number>
</parameter2>
</boolean_operation>
<then>
<do function="Trigger Output" functionTargetID="Temp_MSB" vote_opinion="Off" vote_priority="Medium"></do>
<do function="Change Variable" functionTargetID="variable_temp_msb" vote_opinion="1" vote_priority="Medium"></do>
</then>
</if>
<if fire_on="logic" minimum_delta_vote_time="100" id="Root Function TempMSB_Reset">
<boolean_operation type="not">
<parameter1>
<boolean_operation type="greater than or equal to">
<parameter1>
<variable do="get" name="variable_temp_control_63"></variable>
</parameter1>
<parameter2>
<number>32</number>
</parameter2>
</boolean_operation>
</parameter1>
</boolean_operation>
<then>
<do function="Trigger Output" functionTargetID="Temp_MSB" vote_opinion="On" vote_priority="Medium"></do>
<do function="Change Variable" functionTargetID="variable_temp_msb" vote_opinion="+0" vote_priority="Medium"></do>
</then>
</if>
<if fire_on="logic" minimum_delta_vote_time="100" id="Root Function TempMSB-1_Set">
<boolean_operation type="greater than or equal to">
<parameter1>
<operation type="subtract">
<parameter1>
<variable do="get" name="variable_Temp_Control_63"></variable>
</parameter1>
<parameter2>
<operation type="multiply">
<parameter1>
<variable do="get" name="variable_temp_msb"></variable>
</parameter1>
<parameter2>
<number>32</number>
</parameter2>
</operation>
</parameter2>
</operation>
</parameter1>
<parameter2>
<number>16</number>
</parameter2>
</boolean_operation>
<then>
<do function="Trigger Output" functionTargetID="Temp_MSB-1" vote_opinion="Off" vote_priority="Medium"></do>
<do function="Change Variable" functionTargetID="variable_temp_msb-1" vote_opinion="+1" vote_priority="Medium"></do>
</then>
</if>
<if fire_on="logic" minimum_delta_vote_time="100" id="Root Function TempMSB-1_Reset">
<boolean_operation type="not">
<parameter1>
<boolean_operation type="greater than or equal to">
<parameter1>
<operation type="subtract">
<parameter1>
<variable do="get" name="variable_temp_control_63"></variable>
</parameter1>
<parameter2>
<operation type="multiply">
<parameter1>
<output id="Temp_MSB"></output>
</parameter1>
<parameter2>
<number>32</number>
</parameter2>
</operation>
</parameter2>
</operation>
</parameter1>
<parameter2>
<number>16</number>
</parameter2>
</boolean_operation>
</parameter1>
</boolean_operation>
<then>
<do function="Trigger Output" functionTargetID="Temp_MSB-1" vote_opinion="On" vote_priority="Low"></do>
<do function="Change Variable" functionTargetID="variable_temp_msb" vote_opinion="+0" vote_priority="Medium"></do>
</then>
</if>```
I checked on-line and the two ways I wanted to convert are the major (only) methods of decimal to binary conversion.

One is close to working, but I need to have the function evaluator to see a 'true' or 'on' as a '1' for mathematical operators, the second 'then' do function properly cast it's vote, or some other creative equivalent. This way is working from MSB->LSB in binary.

The other way might work, but it first requires that I can evaluate a number as being odd (or even). I haven't thought this one all of the way through, it's working from LSB->MSB in binary.

To complete my summary, having one-to-many connections from the output of a logical node would be nifty for reducing the number of functions.But....\/

Also, I see where the red lines I drew on top (post#165) could be prevented by placing that set_variable node in-line with the path, but it would require that the logical nodes do not cast a variable, specified as Numeric, with boolean values. imho, it should know the difference, and use 1 and 0 if the recieving variable's type is specified as Numeric.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•