Skip to main content
deleted 47 characters in body
Source Link
SDsolar
  • 1.2k
  • 3
  • 11
  • 35

A const takes up a bit more in RAM if it is used in the program (it does not take up space by the mere declaration).

Definition of hardware pins is not usually redefined later.

For Digital pinspin numbers contained in variables, either can work - such as:


A lot of it comes down to personal preference, however it is clear that #define is more versatile.

A const takes up a bit more in RAM if it is used in the program (it does not take up space by the mere declaration).

Definition of hardware pins is not usually redefined later.

For Digital pins either can work - such as:

For Digital pin numbers contained in variables, either can work - such as:


A lot of it comes down to personal preference, however it is clear that #define is more versatile.

added 32 characters in body
Source Link
SDsolar
  • 1.2k
  • 3
  • 11
  • 35
Instead of using `int``const type,bool true = 1;` and same for `false`

#define true (boolean)1
#define false (boolean)0
Instead of using `int` type,

#define true (boolean)1
#define false (boolean)0
Instead of using `const bool true = 1;` and same for `false`

#define true (boolean)1
#define false (boolean)0
added 656 characters in body
Source Link
SDsolar
  • 1.2k
  • 3
  • 11
  • 35

There is an interesting Arduino Forum thread that discusses other ways to decide:

#define vs. const variable (Arduino forum)

Excertps:

Code substitution:

#define FOREVER for( ; ; )

FOREVER
 {
 if (serial.available() > 0)
   ...
 }

Debugging code:

#ifdef DEBUG
 #define DEBUG_PRINT(x) Serial.println(x)
#else
 #define DEBUG_PRINT(x)
#endif

Defining true and false as Boolean to save RAM

Instead of using `int` type,

#define true (boolean)1
#define false (boolean)0

There is an interesting Arduino Forum thread that discusses other ways to decide:

#define vs. const variable (Arduino forum)

Excertps:

Code substitution:

#define FOREVER for( ; ; )

FOREVER
 {
 if (serial.available() > 0)
   ...
 }

Debugging code:

#ifdef DEBUG
 #define DEBUG_PRINT(x) Serial.println(x)
#else
 #define DEBUG_PRINT(x)
#endif

Defining true and false as Boolean to save RAM

Instead of using `int` type,

#define true (boolean)1
#define false (boolean)0
added 79 characters in body
Source Link
SDsolar
  • 1.2k
  • 3
  • 11
  • 35
Loading
Voltage Divider example code
Source Link
SDsolar
  • 1.2k
  • 3
  • 11
  • 35
Loading
Source Link
SDsolar
  • 1.2k
  • 3
  • 11
  • 35
Loading