Does the arduino support #if macro ?

I use the same code for uno and pro mini, but different pins. I want to make this simple code :

#define ARDUINO_TYPE UNO

#if ARDUINO_TYPE == UNO
  int RECV_PIN = 12;
  
  const int motor_1_control_1 = 2;
  const int motor_1_control_2 = 3;
  const int motor_1_enabled = 4;
  
  const int motor_2_control_1 = 5;
  const int motor_2_control_2 = 6;
  const int motor_2_enabled = 7;
#endif

// The code inside the If should be skipped by the compiler.. 
#if ARDUINO_TYPE == PRO_MINI
  int RECV_PIN = 2;
  
  const int motor_1_control_1 = 10;
  const int motor_1_control_2 = 11;
  const int motor_1_enabled = 12;
  
  const int motor_2_control_1 = 9;
  const int motor_2_control_2 = 8;
  const int motor_2_enabled = 7;
#endif

I get the following errors.

IR_test.ino:23:7: error: redefinition of 'int RECV_PIN' IR_test.ino:11:5: error: 'int RECV_PIN' previously defined here IR_test.ino:25:13: error: redefinition of 'const int motor_1_control_1' .... ....

I'm probably missing something, but I think that the second part of the code should be ignored by the compiler.

Does the arduino support #if macro

No the compiler does.

Where are your braces?

Where are your braces?

if/#elif/#else/#endif statements don't need curly braces.

OP: Look at pins_arduino.h to learn how to properly tell the Arduino type.

The problem is that because UNO and PRO_MINI are not defined, they both have the same value: 0. You could fix it by doing this:

#define UNO 1
#define PRO_MINI 2
#define ARDUINO_TYPE UNO

#if ARDUINO_TYPE == UNO
  int RECV_PIN = 12;

  const int motor_1_control_1 = 2;
  const int motor_1_control_2 = 3;
  const int motor_1_enabled = 4;

  const int motor_2_control_1 = 5;
  const int motor_2_control_2 = 6;
  const int motor_2_enabled = 7;
#endif

// The code inside the If should be skipped by the compiler..
#if ARDUINO_TYPE == PRO_MINI
  int RECV_PIN = 2;

  const int motor_1_control_1 = 10;
  const int motor_1_control_2 = 11;
  const int motor_1_enabled = 12;

  const int motor_2_control_1 = 9;
  const int motor_2_control_2 = 8;
  const int motor_2_enabled = 7;
#endif

However, there's a better way! The Arduino IDE provides a handy way that you can detect which board is selected in the Tools > Board menu, which can be used to automatically change your code accordingly. Give this a try:

#if defined(ARDUINO_AVR_UNO)
  int RECV_PIN = 12;

  const int motor_1_control_1 = 2;
  const int motor_1_control_2 = 3;
  const int motor_1_enabled = 4;

  const int motor_2_control_1 = 5;
  const int motor_2_control_2 = 6;
  const int motor_2_enabled = 7;

#elif defined(ARDUINO_AVR_PRO)
  int RECV_PIN = 2;

  const int motor_1_control_1 = 10;
  const int motor_1_control_2 = 11;
  const int motor_1_enabled = 12;

  const int motor_2_control_1 = 9;
  const int motor_2_control_2 = 8;
  const int motor_2_enabled = 7;
#endif

Information on the board specific macros here: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt

pert Thanks for the better way, I hoped there will be one

That would not help me, I use Optiboot for my Pro Mini's as well so I compile as a Uno.

@OP, it's because UNO does not represent anything so it evaluates to 0. So does PRO_MINI.

Solution is to use solething that is defined:

#define ARDUINO_TYPE 2 //1 for Uno, 2 for Pro Mini

#if ARDUINO_TYPE == 1
  int RECV_PIN = 12;

  const int motor_1_control_1 = 2;
  const int motor_1_control_2 = 3;
  const int motor_1_enabled = 4;

  const int motor_2_control_1 = 5;
  const int motor_2_control_2 = 6;
  const int motor_2_enabled = 7;
#endif

// The code inside the If should be skipped by the compiler..
#if ARDUINO_TYPE == 2
  int RECV_PIN = 2;

  const int motor_1_control_1 = 10;
  const int motor_1_control_2 = 11;
  const int motor_1_enabled = 12;

  const int motor_2_control_1 = 9;
  const int motor_2_control_2 = 8;
  const int motor_2_enabled = 7;
#endif

Or

#define TYPE_UNO 1
#define TYPE_PRO_MINI 2
#define ARDUINO_TYPE TYPE_PRO_MINI

#if ARDUINO_TYPE == TYPE_UNO
  int RECV_PIN = 12;

  const int motor_1_control_1 = 2;
  const int motor_1_control_2 = 3;
  const int motor_1_enabled = 4;

  const int motor_2_control_1 = 5;
  const int motor_2_control_2 = 6;
  const int motor_2_enabled = 7;
#endif

// The code inside the If should be skipped by the compiler..
#if ARDUINO_TYPE == TYPE_PRO_MINI
  int RECV_PIN = 2;

  const int motor_1_control_1 = 10;
  const int motor_1_control_2 = 11;
  const int motor_1_enabled = 12;

  const int motor_2_control_1 = 9;
  const int motor_2_control_2 = 8;
  const int motor_2_enabled = 7;
#endif

[edit]pert was quicker :D Although I do think UNO alone is to general for a macro name.