Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   define irswitch? (http://www.chiefdelphi.com/forums/showthread.php?t=63643)

Lilor 09-02-2008 13:39

define irswitch?
 
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

Re: define irswitch?
 
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:

Code:

#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:

Code:

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:

Code:

// 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

Re: define irswitch?
 
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. =)

Code:

#define IRswitch1 !rc_dig_in01

Alan Anderson 10-02-2008 19:21

Re: define irswitch?
 
Quote:

Originally Posted by whitetiger0990 (Post 695814)
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.


All times are GMT -5. The time now is 18:00.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi