Quote:
Originally Posted by Stuart
#define is your best friend in MPLAB . . or at least your cool kinda crazy uncle
as in
#define optical1 rc_dig_in05
|
To expand on this, there are many good reasons you should do it this way.
What a #define does is essentially does a find-replace on your code before it actually compiles, replacing all of 'optical1' (in this example) with 'rc_dig_in05'. It makes your code more readable because reading 'optical1' makes more sense than 'rc_dig_in05'. It uses no extra memory because you're still ACTUALLY using the already-declared rc_dig_in05 variable instead of making a new one.
Further, if you #define all your stuff in the same place, it makes for a VERY useful section of code that definitively tells you what all your outputs/inputs are. Before I started using #defines to rename all my inputs/outputs, I dreaded the day when someone would ask "hey Bongle, what does the first optical sensor plug into?". You might answer something, then find out during a match you were wrong. This way, you just go to the .h where you #defined everything and say "oh, optical1 is defined to rc_dig_in05, so it goes on digital input 5".
Finally, doing it that way might get around the silly MCC18 error you have right now
As an example in real life, here's our #define section from 2006. We put it all in ifi_aliases.h at the bottom.
Code:
#define turretpan pwm04 // turret left/right motion
#define leftdrive1 pwm05
#define leftdrive2 pwm06
#define rightdrive1 pwm07 // drive motors
#define rightdrive2 pwm08
#define turrettilt pwm09 // turret up/down
#define shooter pwm10 // shooter motor
#define potentInput rc_ana_in03 // potentiometer input
#define gyroInput rc_ana_in01 // gyro input
#define firingPin relay2_fwd // the motor that drove a ball into the shooter wheels
#define limitSwitch rc_dig_in01 // limit switch that detected when the ball-pushing motor had come around