Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Condiional compile depending on board type (Read 2721 times)
roger co
Junior Member
**
Offline


Posts: 14
Joined: Jul 14th, 2014
Condiional compile depending on board type
May 11th, 2015 at 2:47pm
Print Post  
I have a sketch that I want to run on both Uno and Leonardo. Unfortunately the interupt allocation is different between them
For the Uno (and Mega2560) Int0 is pin 2 and Int1 is pin 3, for Leonardo Int1 is pin 2 and Int0 is pin 3
Is there a way of detecting at compile time whether the target is Uno or Leonardo so that I can change the value of a const accordingly
like:
#if (TARGET=='Leonardo')
     static const int HRInt = 1;
#else
     static const int HRInt = 0;
#endif
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Condiional compile depending on board type
Reply #1 - May 11th, 2015 at 2:50pm
Print Post  
Yes there are a few ways.

I suggest you switch on tools>visual micro>verbose

Then build once for each board and look at the output. You will see a number of -D defines in the compiler statements. you can use any of them in your code, for example, #if BOARD

Thanks
  
Back to top
IP Logged
 
roger co
Junior Member
**
Offline


Posts: 14
Joined: Jul 14th, 2014
Re: Condiional compile depending on board type
Reply #2 - May 12th, 2015 at 2:11pm
Print Post  
Thanks for the clue. This works:
#if (ARDUINO_AVR_UNO)
     static const int HRInt = 0;            // Interrupt for HR = 0 for Uno, 1 for Leonardo
     String UnitID = "UNO";
#elif (ARDUINO_AVR_LEONARDO)
     static const int HRInt = 1;            // Interrupt for HR = 0 for Uno, 1 for Leonardo
     String UnitID = "LEONARDO";
#else
     static const int HRInt = 0;
     String UnitID = "Default";
#endif

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint