I'd rather understand the define than avoid it as it looks like it will have a lot of utility.
...
The way #define is used here is simple to understand so let's see if I can present it as so for you.
#define is a way to ask the pre-compiler part of the compile process to do text replacement/modification. The pre-compiler hands over a modified source file to the compiler to compile.
// ====================================
// Simple case:
// ====================================
In its simplest form:
#define
myDigitalRead digitalReadV2Every time when it sees the word
myDigitalRead in your source (other than comments), it is replaced with the word
digitalReadV2Imagine you have these functions in your code:
digitalReadV1(value1, value2...) // functioning old version
digitalReadV2(value1, value2...) // working on this new version
and elsewhere in the codes, you have many calls it to all over the place:
result = myDigitalRead(something, something...)All occurrences will turn into:
result = digitalReadV2(something, something...)Now, if you want to call the old function again, all you have to do is change the #define statement to:
#define myDigitalRead
digitalReadV1Now all occurrences will turn into:
result = digitalReadV1(something, something...)// -----------------------------------------------------------
// I have two type of I2C with different addresses and size
// and the code supports them
#define LCDxSize 20
#define LCDySize 4
#define LCDAddress 0xfb // I2C address of current LCD installed
// with all my codes using the #defined value above, I can change LCD without
// hunting all over my code when I switch LCD
// ====================================
// Now more complicated #define with parameter:
// ====================================
#define myDoublePrint(label,value) Serial.print(label);Serial.print(value);
// now, you can just use myDoublePrint and the pre-compiler will convert that
// into two Serial.print for you.
// This would be a good way to compare memory use by make double calls verses
// changing the #define and make it call a function that do the two printing.
//
// ----------- Example: -----------
//
make the choice by commenting out one of the #define below
#define myDoublePrint(label,value) { Serial.print(label);Serial.print(value); }
#define myDoublePrint(label,value) myNewFunction((label),(value))
void myNewFunction(char *label,float value) {
Serial.print(label);Serial.print(value);
}
//-------------------------------------------------------
Hope that helps you understand simple #define. If it does, you may even use
#if def(something)
some codes here in between
#endif
And then there are more complicated ways of using #define to achieve more... When you feel comfortable with using #define, lots of fun to research what else can be done
By the way, which IDE are you using?