Skip to content

LED_BUILTIN in variant header file needs to be a define #2769

Closed
@bperrybap

Description

@bperrybap

There was lots of discussion about this several years ago on the Arduino developers lists and the resolution was to always ensure that there is a LED_BUILTIN define so that sketches and libraries could run time detect the presence of a built in LED.
So for years there has been a LED_BUILTIN define on all the Arduino.cc supplied AVR cores and some of the newer non AVR cores.
All the variant files in the esp8266 core declare LED_BUILTIN as a static const uint8_t
The problem with not having a define is that it breaks any code that depends on LED_BUILTIN as being a define to enable/disable use of a built in LED.
There are two solutions

  • change the const declaration to be a define (which is what the Arduino.cc devs did in the AVR core)
  • create a define that matches the variable name.

Either will work.
My suggestion would be to use the latter and create a define that matches the variable name.
i.e.

#define LED_BUILTIN LED_BUILTIN
static const uint8_t LED_BUILTIN = 2;//new ESP-12E GPIO2

That way you get the best of both worlds.
A define that code can use to compile time verify the existence of a built in led and a variable by the same name that allows for a typed variable rather than using a simple define.

This ensures full backward compatibility with other cores and older IDEs.
Doing something like adding a new PIN_LED_BUILTIN define is not a workable solution as it is not backward compatible and would require updating code ot use messy Arduino defines to try to compile detect which core and which core version is being used to know what defines or variable names to use.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions