View Single Post
  #2   Spotlight this post!  
Unread 09-02-2008, 13:44
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
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.