
Re: Questions for MHTS! Please help :)
These are call macros. Like what amcerbu said, #define is a pre-processor command. It allows you to associate a name to anything. For example, when I defined DEADBAND_THRESHOLD as 15, it means whenever the pre-processor finds DEADBAND_THRESHOLD in the code, it is going to replace it with whatever it is associated with, in this case the constant 15. The benefit of using "defined constants" is that you may use the constant in a lot of places. If, for example, you decided to change the deadband threshold to say 20, you need to search and find all instances of the value 15 and replace them with 20. However, if you use the DEADBAND_THRESHOLD name everywhere in your code, you can just change the define line to 20 and it will be replaced everywhere. Giving it a meaningful name also makes the code a lot easier to understand. There are many creative ways of using macros. For example, you can make macros look like functions.
Since we have defined BOUND(x) as a macro, it means when the pre-processor sees BOUND(joystick.joy1_y1), it is going to replace the statement with what BOUND is defined to and substituting x with joystick.joy1_y1. So it becomes:
It makes the code a lot cleaner and easier to understand.