I'm writing an Arduino library to communicate with an I2C device, and I'm wondering what the best way is to declare all the register addresses so as to save memory.
Using #defines
:
#define REGISTER_MOTOR_1_MODE 0x44
#define REGISTER_MOTOR_2_MODE 0x47
Or using static const
:
static const uint8_t REGISTER_MOTOR_1_MODE = 0x44;
static const uint8_t REGISTER_MOTOR_2_MODE = 0x47;
(Obviously I have more than just two registers I need to declare, but I thought two would illustrate the point just fine)
#define LED_MASK 0x01<<2
. A safe(r) way to write that would be#define LED_MASK (0x01<<2)
. See also stackoverflow.com/questions/6542270/…