Skip to main content
2 of 4
extended according to @EdgarBonet's comments
KIIV
  • 4.9k
  • 1
  • 14
  • 23

Arduino defines some macros so you can use conditional compilation. For example these are from boards.txt:

  • use ARDUINO_AVR_PROMICRO if it's specific for board variant
  • use DARDUINO_ARCH_AVR if it's specific for Arduino with AVR

Also avr-gcc defines macros according to cpu settings (this should be similar for other platforms too):

  • use __AVR_ATmega32U4__ if it's specific for only one MCU
  • use __AVR__ if it's compatible with all AVR based MCUs

And code examples:

#if defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__)
// something for ATmegaXX8 family...
#else
// ...
#endif

#ifdef __AVR__ 
// Code related to AVR
#else
// Code for other architectures
#endif
KIIV
  • 4.9k
  • 1
  • 14
  • 23