Pressure switch code

under which heading do we put the pressure switch code!!! :yikes:

I don’t quite understand your question - do you mean which function should it go in? It really doesn’t matter too much, although I think that ProcessDatafromMasterUP is the preferred place.

Let me see what I can do. . .

Our pressure switch code is wicked simple:

The pressure switch is on digital input 8, and the compressor is on relay 8.

in the initialization routine

relay8_fwd = 1; //Start with compressor on

In the default routine:

relay8_fwd = 1; // If low air pressure, turn on
relay8_fwd = 0; // If high air pressure, turn off

if your not a fan of bulky code:

relay8_fwd = !rc_dig_in18;
relay8_rev = 0;

from there, the RC has a built in pull up on the (s) line. soo you connect the white to one side of the switch and the black to the otherside of the switch. that is, if your using a pwm style color coded cable. you dont need the positive at all. the pressure switch is N.C. meening that with this setup the normal signal will be 0 and when it closes it will be 1. therefore !rc_dig_in18 yeilds 1 when it is normal and 0 when it goes over. no if statment needed.

bulky? I was just trying to keep it simple. . . :frowning:

every “if” statment is at least 4 lines in ASM. add an “else” and that adds 6 more lines. a boolean assinment is only 2 lines. but whatever

correct me if i am wrong but isn’t the code for the pressure switch already in the default as long as you hook up the switch to digital input 18 and the pump to relay 8?

Yes. The default code contains the following lines, I believe:

relay8_fwd = !rc_dig_in18;
relay8_rev = 0;

Connect the pressure switch to the white and black wires of a cable plugged into digital input 18, and you should be all set (assuming you’ve connected the compressor’s relay to relay output 8).

There is a difference between it being easy for a human to read, and easy for a computer to understand.

Personally, I choose what is easier for me to understand, and in the 2% of cases where it needs to be fast, I write well commented assembly.

If people ask a question, I’ll give easy to understand code. I just wrote that up real quick, and didn’t bother to shove it in as few lines of code as possible.

As far as four lines, six lines, or two lines in ASM- this isn’t ASM.

but it is compialed as such :cool:

Check out the listing of what the compiler produces. An “if” produces a bunch of assembly, but so does an assignment of bit-sized values.