@dbemowsk said in MultiSensor - relays, temp, hum, PIR, gesture with various controller overrides:
... I think it is best to use compiler variables. They get rid of the needless use of variable storage space, even if the sketch is small. IMHO, program variables should be used for values that may/will change in your sketch
The problem with using the #define directive for a constant is that they are not strongly typed. That is, suppose you are making a comparison, you may not realize that you are comparing a signed to unsigned number.
You can see this if you compile this example with verbose on:
#define LIMIT 6
const unsigned int limit = 6;
void setup()
{
int myVar = 5;
if(myVar > LIMIT){};
if(myVar > limit){};
}
void loop() {}
in C++, it is generally preferred to use the const keyword over a #define directive; both methods will store the "variable" in FLASH, saving SRAM as you pointed out.
There is (of course) a lot of discourse on this topic (see Stack Overflow).
So there are benefits to using #define. A #define at the top of a program does usually get seen by the programmer (or you, later on, after a hiatus) where they/you may not notice a regular definition on a quick glance #define sort of sticks out in the crowd.
Perhaps that is why you see so much of the #define directive in Arduino programming.