Skip to content

DS_CAP_SYS_LED

Denis Stepanov edited this page May 14, 2021 · 7 revisions

DS_CAP_SYS_LED — On-board LED

Description

This capability adds support for an on-board LED. The following fields are implemented:

Field Description Default Value
JLed System::led Builtin LED LED_BUILTIN

LED pin is determined by LED_BUILTIN macro, which is normally set up automatically with the board selection in Arduino. If you are using a Generic ESP8266 Module, be sure to select the right pin via Tools -> Builtin Led Arduino menu (it is 1 for ESP-01 and 2 for ESP-01S).

The actual LED functionality is implemented with JLed library. DS-System library exposes led object which gives full access to JLed methods.

Requires

  • JLed — LED support library

Cooperates With

  • DS_CAP_SYS_NETWORK — if network is enabled in presence of LED capability, its System::connectNetwork() will change signature to take an optional LED object. If passed, it will be used to signal Wi-Fi connection progress;
  • DS_CAP_WIFIMANAGER — if Wi-Fi manager is enabled, the LED will be lit steadily while Wi-Fi manager is running.

Conflicts With

  • DS_CAP_SYS_LOG_HW — in some boards, like ESP-01, the on-board LED is controlled by a serial TX pin. This means that, if both LED and syslog capabilities are enabled, a conflict over pin control may happen. Both features will likely misbehave in this case. To decrease such possibility, library will issue a compilation warning:

    #warning "In ESP8266, capabilities DS_CAP_SYS_LED and DS_CAP_SYS_LOG_HW may conflict on a pin. Define DS_LED_VS_SERIAL_CHECKED_OK to suppress this warning"
    

    In many cases, serial TX and on-board LED will use different pins. It is also possible to reallocate serial TX pin at runtime (the on-board LED is soldered to the pin and cannot be altered). The library has no means to detect if there would be actually a conflict in your case or not. If you are sure that there is no conflict, define DS_LED_VS_SERIAL_CHECKED_OK in MySystem.h in order to suppress the compilation warning.

Usage

MySystem.h:

#define DS_CAP_SYS_LED      // Enable builtin LED

#include "System.h"         // System global definitions

sketch.ino:

#include "MySystem.h"

using namespace ds;

void setup() {
    System::begin();
    System::led.Blink(1000, 2000).Forever();
}

void loop() {
    System::update();
}

Mandatory Calls

System::begin() Required
System::update() Required

Certain LED states, such as fully "on" or fully "off", do not warrant use of System::update(). Some other, such as glowing effect, require System::update() to be called with little-to-no delay. See JLed documentation for details.

Examples

Bugs

None.

Availability

Version 1.0 or later.

See Also

None.