Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
In Arduino.h, __AVR_ATtiny85__ is used (capital T). Not sure if it makes any difference though. –  geometrikal 9 hours ago
    
@geometrikal Nice catch (typo)... edited. Thanks! –  Annonomus Penguin 8 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.