4

I am using thermocouples and downloaded the MAX6675 library. I wondered what the value of the ARDUINO constant in the following lines is for.

#if ARDUINO >= 100
  lcd.write((byte)0);
#else
  lcd.print(0, BYTE);
#endif
  lcd.print("C ");
  lcd.print(thermocouple.readFahrenheit());
#if ARDUINO >= 100
  lcd.write((byte)0);
#else
  lcd.print(0, BYTE);
#endif
  lcd.print('F');

I have searched for the answer but have turned up very little info. I can print out the value with the following line, but I still can't find out what it means.

Serial.println(ARDUINO);

Eugene
  • 335
  • 2
  • 6

1 Answers1

11

The ARDUINO constant gives the version of the Arduino environment being used.

For example, 22 was for the old Arduino 22 IDE and 100 is for version 1.0 of the Arduino environment. The value of the ARDUINO constant in the latest Arduino release (1.6.5) appears to be 10605.

There were some significant changes in the Arduino APIs between the old versions (e.g. 22) and the 1.0 release. The value of ARDUINO can be used to conditionally compile different code for different versions of the API.

In your example it appears that in the version 1.0+ environment you need to use lcd.write() but in the old environments you had to use lcd.print. Testing the value of ARDUINO allows the same code to work in both environments.

mttrb
  • 8,297
  • 3
  • 35
  • 57
  • Thanks for the great explanation! – Eugene Jun 19 '15 at 09:36
  • 1
    Do you know where this value is actually assigned? My setup in eclipse is breaking because an incorrect value of ARDUINO! – Fabio Aug 17 '15 at 02:34
  • 2
    It is a while since I looked at this so don't quote me but I seem to recall coming to the conclusion that the Arduino IDE sets the `ARDUINO` value define as a parameter to the compilers command line invocation. – mttrb Aug 17 '15 at 06:11
  • Now I have found it too: you have to add `-DARDUINO=100` as compiler argument (with correct version number evidently...). Btw: with `-Dconstant` or `-Dconstant=value` as argument you can define or define and specify any constant to the compiler! – Fabio Aug 18 '15 at 18:37
  • If you are trying to compile Arduino sketches in Visual Studio CODE using the Arduino extension, you may need to set this constant in the c_cpp_properties.json configuration file. When not set, all those libraries that are doing conditional compiling against it will likely fail. Add "ARDUINO=10800" (or whatever version is appropriate) to the "defines" array. – Steve In CO Jul 30 '20 at 18:55