Log in

View Full Version : define irswitch?


Lilor
09-02-2008, 13:39
how do you define the ir board commands in the program.

this is what we have but we don't know if it is right

#define IRswitch1
#define IRswitch2
#define IRswitch3
#define IRswitch4

or can someone post how they defined the IRswitch?

psy_wombats
09-02-2008, 13:44
You need to use #define to assign a value to the IRswtich things. They are only placeholders, the compiler will go through and replace all "IRswitch1" with whatever you put after it. So it would like:

#define IRswitch1 rc_dig_in01
#define IRswitch2 rc_dig_in02
#define IRswitch3 rc_dig_in03
#define IRswitch4 rc_dig_in04


Assuming you used those four for your IR wiring. And then to use them:

if (!IRswitch1) //If the IR has been pressed
auto_routine_1(); //Do whatever when switch is down
}

Just as an example, here's how we defined it:

// IR Inputs
#define IR_DIG_1 rc_dig_in07
#define IR_DIG_2 rc_dig_in08
#define IR_DIG_3 rc_dig_in09
#define IR_DIG_4 rc_dig_in10

// IR Values
#define IR_DISCONNECTED (IR_DIG_1 && IR_DIG_2 && IR_DIG_3 && IR_DIG_4)
#define IR_1 (IR_DIG_1 && !IR_DISCONNECTED)
#define IR_2 (IR_DIG_2 && !IR_DISCONNECTED)
#define IR_3 (IR_DIG_3 && !IR_DISCONNECTED)
#define IR_4 (IR_DIG_4 && !IR_DISCONNECTED)

That way you won't get confused when the IR board is out.

whitetiger0990
10-02-2008, 12:49
We NOT our digital ins right there at the macro. Like what psy_wombats said, but I think that it reads better in the if statements. Digital inputs become false when the circuit is closed. =)

#define IRswitch1 !rc_dig_in01

Alan Anderson
10-02-2008, 19:21
Digital inputs become false when the circuit is closed.

That's correct for switches or "open-collector output" sensors that complete a connection to ground. But the IR sensor is not that kind of circuit. It provides a logic level output, with the digital input resting at zero and going to one when the signal is recognized.