Quote:
|
Originally Posted by dcbrown
1. Defines with arguments and these showing up in the user functions list.
For example:
#define SetLeftWheel( _pwm ) SetPWM(2, _pwm)
Yeah, we could code a routine called SetLeftWheel() that simply calls SetPWM(), but the call stack isn't that large and we could end up wasting a lot of its stack entries on simple redirection. The define just makes it easier for us to forget which ports/pins/interrupts go together to make up a specific feature on our robot. A feature for Pro mode only maybe?
|
Depending on exactly what you are trying to accomplish, you might try what I've done:
I defined global constants such as R_DRIVE_PWM and LIMIT_SW_1_INPUT as numbers (3 and 1, in this case). Then I use PWM Control and Limit Switch blocks and select the corresponding constants from the dropdown. It ends up like so:
Code:
SetPWM (R_DRIVE_PWM, speed)
and
Code:
sw1 = GetDigitalInput (LIMIT_SW_1_INPUT)
This allows me to modify almost everything I need to tweak right from the Macros and Constants dialog without having to search through all my code and change each place I set my drive speed, for example. It also makes the code easier for a non-programmer or a newcomer to understand.