Skip to content

Library manages an LED, usually built-in led for signalling purposes.

License

Notifications You must be signed in to change notification settings

mrkaleArduinoLib/gbj_appled

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbj_appled

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.

Fundamental functionality

  • 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

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.

Dependency

  • gbj_timer: Library for executing internal timer within an instance object loaded from the file gbj_timer.h.

Arduino platform

  • 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.

Espressif ESP8266 platform

  • Arduino.h: Main include file for the Arduino platform.

Espressif ESP32 platform

  • Arduino.h: Main include file for the Arduino platform.

Interface

Getters

Setters

gbj_appled()

Description

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.

Syntax

gbj_appled(byte pinLed, bool reverse, bool block)

Parameters

  • 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

Returns

Object performing led management.

Back to interface

begin()

Description

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.

Syntax

void begin()

Parameters

None

Returns

None

Back to interface

run()

Description

The method executes an led blinking and should be called frequently, usually in the loop function of a sketch.

Syntax

void run()

Parameters

None

Returns

None

See also

blink(), blinkHurry(), blinkFast()

blinkPattern()

Back to interface

block(), free()

Description

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.

Syntax

void block()
void free()

Parameters

None

Returns

None

See also

isBlocked(), isFree()

enable(), disable()

Back to interface

enable(), disable()

Description

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.

Syntax

void enable()
void disable()

Parameters

None

Returns

None

See also

isEnabled(), isDisabled()

setAbility()

block(), free()

begin()

Back to interface

setAbility()

Description

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.

Syntax

void setAbility(bool enabled)

Parameters

  • 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

Returns

None

See also

isEnabled(), isDisabled()

begin()

Back to interface

on(), off(), toggle()

Description

The particular method sets corresponding steady visibility of the led if it is enabled, either switch it on, off, or changes its state.

Syntax

void on()
void off()
void toggle()

Parameters

None

Returns

None

Back to interface

blink(), blinkHurry(), blinkFast()

Description

The particular method starts corresponding blinking mode of an led if it is enabled, either normal, hurry, or fast blinking.

Syntax

void blink()
void blinkHurry()
void blinkFast()

Parameters

None

Returns

None

See also

blinkPattern()

Back to interface

blinkPattern()

Description

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.

Syntax

void blinkPattern(byte blinks)

Parameters

  • blinks: Number of blinks in the bursts of hurry blinking.
    • Valid values: 2 - 255
    • Default value: 3

Returns

None

See also

blinkHurry()

Back to interface

restoreMode()

Description

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.

Syntax

void restoreMode()

Parameters

None

Returns

None

Back to interface

isBlocked(), isFree()

Description

The particular getter returns flag determining whether corresponding accessibility of the led is valid.

Syntax

bool isBlocked()
bool isFree()

Parameters

None

Returns

Boolean flag about validity of corresponding led's accessibility.

See also

block(), free()

Back to interface

isEnabled(), isDisabled()

Description

The particular getter returns flag determining whether corresponding ability of the led is valid.

Syntax

bool isEnabled()
bool isDisabled()

Parameters

None

Returns

Boolean flag about validity of corresponding led's ability.

See also

enable(), disable()

Back to interface

isLit(), isDim()

Description

The particular getter returns flag determining whether corresponding led is valid, i.e., the led lights or is dimmed.

Syntax

bool isLit()
bool isDim()

Parameters

None

Returns

Boolean flag about validity of corresponding led's state. If the led is blocked, the method always returs false flag.

Back to interface

isOn(), isOff()

Description

The particular getter returns flag determining whether corresponding steady visibility mode of the led is valid.

Syntax

bool isOn()
bool isOff()

Parameters

None

Returns

Boolean flag about validity of corresponding led's steady visibility. If the led is blocked, the method always returs false flag.

See also

on(), off(), toggle()

Back to interface

isBlinking(), isPatterned()

Description

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.

Syntax

bool isBlinking()
bool isPatterned()

Parameters

None

Returns

Boolean flag about validity of corresponding led's blinking. If the led is blocked, the method always returs false flag.

See also

blink(), blinkHurry(), blinkFast()

blinkPattern()

Back to interface

getStatusOn(), getStatusOff()

Description

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".

Syntax

String getStatusOn()
String getStatusOff()
String getStatus()

Parameters

None

Returns

Textual flag representing enabled or disabled led state.

See also

getStatus()

Back to interface

getStatus()

Description

The getter returns textual representation of the current led's state, i.e., flag about its availability.

Syntax

String getStatus()

Parameters

None

Returns

Textual flag representing current led state.

See also

getStatusOn(), getStatusOff()

Back to interface

getMode(), getModeText()

Description

The getter returns either numerical or textual representation of the current led's modus, i.e., its current visual function.

Syntax

byte getMode()
String getModeText()

Parameters

None

Returns

Numerical or textual representation of current led modus.

See also

getBlinks()

Back to interface

getBlinks()

Description

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.

Syntax

byte getBlinks()

Parameters

None

Returns

Number of blinks used at pattern blinking modus.

See also

getMode(), getModeText()

Back to interface

forceLit()

Description

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.

Syntax

void forceLit()

Parameters

None

Returns

None

Back to interface

About

Library manages an LED, usually built-in led for signalling purposes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages