Home

How to Name an I/O Pin

It is a good design practice to assign meaningful names to I/O pins instead of just referring to them by number. If, for some reason (such as changing microcontroller boards), you need to change I/O pin assignments, you will only need to make the change in one place.

// Name an I/O pin with a preprocessing macro
#define SENSOR1 3             // Some kind of digital sensor input

// Name an I/O pin with a constant
const uint8_t ACTUATOR1 = 4;  // Some kind of digital actuator output

void setup()
{
  pinMode(SENSOR1,   INPUT);
  pinMode(ACTUATOR1, OUTPUT);
  pinMode(2,         OUTPUT); // Unnamed I/O pins are discouraged!
}

void loop()
{
}

Home


Questions or comments to phil@munts.net