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
asked Sep 13, 2014 at 12:38
1 Answer 1
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
answered Sep 13, 2014 at 12:50
-
In
Arduino.h
,__AVR_ATtiny85__
is used (capitalT
). Not sure if it makes any difference though.geometrikal– geometrikal2014年09月13日 12:52:45 +00:00Commented Sep 13, 2014 at 12:52 -
2alternatively using 1.5.+ IDE you can test against the board type you are building. See Arduino-IDE-1.5---3rd-party-Hardware-specification. Example "#if defined(ARDUINO_AVR_UNO)" or ARDUINO_AVR_MEGA2560 or ARDUINO_AVR_LEONARDO, etc...mpflaga– mpflaga2014年09月14日 03:55:43 +00:00Commented Sep 14, 2014 at 3:55