15

I use my Arduino IDE to either upload my sketch to a Arduino or ATTiny or ATmega328. As you know each device can have a different pinout. Does the Arduino compiler support ifdef, depending on the board I am connected to?

For example

#ifdef Attiny85
       a=0; b=1; c=2;
#else
       // arduino
       a=9; b=10; c=11;
#endif
PhillyNJ
  • 1,178
  • 3
  • 10
  • 20

1 Answers1

15

Yes. Here is the syntax:

#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
    //Code here
#endif

You can also do something like this for the Mega:

#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    //Code here
#endif

Assuming the implementation for the ATtiny is correct, your code should be like this:

#if defined (__AVR_ATtiny85__)
       a=0; b=1; c=2;
#else
       //Arduino
       a=9; b=10; c=11
#endif
Anonymous Penguin
  • 6,365
  • 10
  • 34
  • 62