This is an application library, which is used usually as a project library for particular PlatformIO project. It encapsulates the functionality of a signal LED
, which is usually built-in LED of a microcontroller development board. The encapsulation provides following advantages:
- Functionality is hidden from the main sketch.
- The library follows the principle
separation of concerns
. - The library is reusable for various projects without need to code a led management.
- Update in library is valid for all involved projects.
- The library controls visibility (on, off) an led always in the same way regardless the led is active high (arduino, ESP32) or active low (ESP8266).
- It controls accessibility of an led's GPIO, i.e., can totally avoid manipulation with the corresponding pin. It is neccessary for microcontroller, where builtin led is connected to serial TX pin, so that using the led and serial monitor at once is not possible.
- It controls accessibility (blocked, free) of the led.
- It controls ability (enabled, disabled) of the led.
- It controls blinking (steady, patterned) of the led.
- The library utilizes internal timer for blinking.
Internal parameters are hard-coded in the library usually as enumerations and have no setters and getters associated.
- Time period for normal blinking (
500 ms
): This parameter for 1 blink per second (1 Hz frequency) is suitable for signalling normal operation of a microcontroller. - Time period for hurry blinking (
200 ms
): This parameter for 5 blinks per 2 second (2.5 Hz frequency) is utilized for patterned blinking and suitable for signalling specific errors by number of blinks in a burst. - Time period for fast blinking (
100 ms
): This parameter for 5 blinks per second (5 Hz frequency) is suitable for signalling abnormal, usually general erroneous operation of a microcontroller.
- gbj_timer: Library for executing internal timer within an instance object loaded from the file
gbj_timer.h
.
- Arduino.h: Main include file for the Arduino SDK.
- inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.
- Arduino.h: Main include file for the Arduino platform.
- Arduino.h: Main include file for the Arduino platform.
- gbj_appled()
- begin()
- run()
- block()
- free()
- enable()
- disable()
- on()
- off()
- toggle()
- blink()
- blinkHurry()
- blinkFast()
- blinkPattern()
- forceLit()
- isBlocked()
- isFree()
- isEnabled()
- isDisabled()
- isLit()
- isDim()
- isOn()
- isOff()
- isBlinking()
- isPatterned()
- getStatusOn()
- getStatusOff()
- getStatus()
- getMode()
- getModeText()
- getBlinks()
Constructor creates the class instance object and initiates state of the led, especially values for turned on or off state depending on reversebility of the led.
gbj_appled(byte pinLed, bool reverse, bool block)
-
pinLed: Number of a GPIO pin, where the signalling led is connected. Usually it is a built-in led or an auxilliary led (NodeMCU).
- Valid values: available output GPIO pins
- Default value: LED_BUILTIN (depends on platform)
-
reverse: Flag determining polarity of the led, i.e., whether the led works in reverse mode (active low) or in direct mode (active high).
- Valid values: true or false
- Default value: true (preferrably for ESP8266, ESP)
-
block: Flag whether the GPIO pin for led is not controlled alltogether. It is suitable at ESP8266-01, where builtin led is connected to serial TX pin, so that the using led and serial monitor at once is not possible.
- Valid values: true or false
- Default value: false
Object performing led management.
The initialization method of the instance object, which should be called in the setup section of a sketch.
- The method activates an led pin and enables the led.
- The method turns the LED off in order not to lit until it is turned on in a sketch exactly.
- The ability can be change later with corresponding method.
void begin()
None
None
The method executes an led blinking and should be called frequently, usually in the loop function of a sketch.
void run()
None
None
blink(), blinkHurry(), blinkFast()
The methods manipulate accessibility of the led's GPIO pin, either blocks or frees it.
- Blocking the led is useful when a led's GPIO pin should not be allocated, e.g, when it is built-in one and is used for serial communication.
- After changing the accessibility of a led's GPIO pin during the firmware run, its mode should be set exactly in a sketch accordingly to the new usage of it.
- When the led is blocked, it is turned off even if the led is enabled.
void block()
void free()
None
None
The methods manipulate ability of the led, either enables or disables it.
- If the led is disabled, the internal code is working the same way as in enabled mode, but the physical manipulation with led's GPIO pin is suppressed as it was at blocked led.
void enable()
void disable()
None
None
The method sets ability of the led by the value of input argument. It is a setter for the input argument of the method begin.
void setAbility(bool enabled)
- enabled: Flag defining the ability of an LED. If disabled, the led is ignored entirely and never lits.
- Valid values: true or false
- Default value: none
None
The particular method sets corresponding steady visibility of the led if it is enabled, either switch it on, off, or changes its state.
void on()
void off()
void toggle()
None
None
The particular method starts corresponding blinking mode of an led if it is enabled, either normal, hurry, or fast blinking.
void blink()
void blinkHurry()
void blinkFast()
None
None
The method starts patterned blinking mode of an led if it is enabled consisting of periodic bursts of input number of hurry blinks followed by a pause with the led turned off valid for normal blinking.
void blinkPattern(byte blinks)
- blinks: Number of blinks in the bursts of hurry blinking.
- Valid values: 2 - 255
- Default value: 3
None
The method restores the previous led modus or number of blinks in case of patterned blinking.
- It is useful at temporary changing led mode, e.g., to "on" at long lasting blocking operations and then to return to previous (original) mode.
void restoreMode()
None
None
The particular getter returns flag determining whether corresponding accessibility of the led is valid.
bool isBlocked()
bool isFree()
None
Boolean flag about validity of corresponding led's accessibility.
The particular getter returns flag determining whether corresponding ability of the led is valid.
bool isEnabled()
bool isDisabled()
None
Boolean flag about validity of corresponding led's ability.
The particular getter returns flag determining whether corresponding led is valid, i.e., the led lights or is dimmed.
bool isLit()
bool isDim()
None
Boolean flag about validity of corresponding led's state. If the led is blocked, the method always returs false flag.
The particular getter returns flag determining whether corresponding steady visibility mode of the led is valid.
bool isOn()
bool isOff()
None
Boolean flag about validity of corresponding led's steady visibility. If the led is blocked, the method always returs false flag.
The particular getter returns flag determining whether corresponding steady or patterned blinking mode of the led is valid.
- In fact, the getter determines whether the internal timer is active and runs.
bool isBlinking()
bool isPatterned()
None
Boolean flag about validity of corresponding led's blinking. If the led is blocked, the method always returs false flag.
blink(), blinkHurry(), blinkFast()
The particular getter returns textual flag representing enabled or disabled state of the led.
- The enabled led state is represented with the string "ON".
- The disabled led state is represented with the string "OFF".
String getStatusOn()
String getStatusOff()
String getStatus()
None
Textual flag representing enabled or disabled led state.
The getter returns textual representation of the current led's state, i.e., flag about its availability.
String getStatus()
None
Textual flag representing current led state.
The getter returns either numerical or textual representation of the current led's modus, i.e., its current visual function.
byte getMode()
String getModeText()
None
Numerical or textual representation of current led modus.
The getter returns number of blinks utilized at pattern blinking led modus.
- The getter is usefull only in pattern blinking mode, even if returns the blinks number in either case.
byte getBlinks()
None
Number of blinks used at pattern blinking modus.
The method forcibly turns the led on without changing its current modus, which should not be off mode and led is not blocked or disabled.
- This is useful at the beginning of long blocking operation to ensure the led is physically turned on.
void forceLit()
None
None