Skip to content

Latest commit

 

History

History
125 lines (68 loc) · 6.54 KB

API.md

File metadata and controls

125 lines (68 loc) · 6.54 KB

FadeLED library API

FadeLED (base class)

FadeLED(const byte pin, const bool invert = false)

The constructor creates an instance of a FadeLED object. This constructor should not be called directly by application code, but is called by the constructors of the FadeLED_Lin and FadeLED_Exp derived classes.

NOTE: On some Arduino devices, such as the Arduino UNO, the LED_BUILTIN pin does not support PWM output.

Arguments

  • pin: const byte: PWM-capable GPIO pin which will drive an LED connected to it.
  • invert: const bool: If false, the GPIO pin will be driven HIGH when the FadeLED object goes to its on state. If invert if true, the on state drives the GPIO pin LOW. The default is false (don't invert).

virtual bool update()

Checks if it is time to update the state of the FadeLED object. This method should not be called directly by the user's application code; it will be called by the FadeLED_Lin, FadeLED_Exp, and FadeLED_Func update() methods from the Arduino sketch's loop() function.

Returns

  • bool: true if object's state has been updated.

bool read() const

Gets the state of the object.

Returns

  • bool: Returns true if LED is either fully on or is fading from off to on, and false if LED is fully off or fading from on to off.

void write(bool state)

Sets the state of the object to either turning-on or turning-off.

Arguments

  • state: bool: If true, sets object to turning-on state, otherwise it is set to turning-off.

FadeLED_Lin

FadeLED_Lin(const byte pin, const uint32_t onTime, const uint32_t offTIme, const bool invert = false)

The constructor creates an instance of a FadeLED_Lin object, which in turn creates an instance of the FadeLED base class. The FadeLED_Lin object inherits the read() and write() methods from the base class.

NOTE: On some Arduino devices, such as the Arduino UNO, the LED_BUILTIN pin does not support PWM output.

Arguments

  • pin: const byte: PWM-capable GPIO pin which will drive an LED connected to it.
  • onTime: const uint32_t: Time in milliseconds that GPIO pin takes to go from fully-off to fully-on.
  • offTime: const uint32_t: Time in milliseconds that GPIO pin takes to go from fully-on to fully-off.
  • invert: const bool: If false, the GPIO pin will be driven HIGH when the FadeLED object goes to its on state. If invert is true, the on state drives the GPIO pin LOW. The default is false (don't invert).

virtual bool update()

Checks if it is time to update the state of the FadeLED_Lin object. This method should be called from within the Arduino sketch's loop() function.

Returns

  • bool: true if object's state has been updated.

FadeLED_Exp

FadeLED_Exp(const byte pin, const unsigned int onTime, const unsigned int offTIme, const bool invert = false)

The constructor creates an instance of a FadeLED_Exp object, which in turn creates an instance of the FadeLED base class. The FadeLED_Exp object inherits the read() and write() methods from the base class.

NOTE: On some Arduino devices, such as the Arduino UNO, the LED_BUILTIN pin does not support PWM output.

Arguments

  • pin: const byte: PWM-capable GPIO pin which will drive an LED connected to it.
  • onTime: const uint32_t: Time in milliseconds that GPIO pin takes to go from fully-off to fully-on.
  • offTime: const uint32_t: Time in milliseconds that GPIO pin takes to go from fully-on to fully-off.
  • invert: const bool: If false, the GPIO pin will be driven HIGH when the FadeLED object goes to its on state. If invert if true, the on state drives the GPIO pin LOW. The default is false (don't invert).

virtual bool update()

Checks if it is time to update the state of the FadeLED_Exp object. This method should be called from within the Arduino sketch's loop() function.

Returns

  • bool: true if object's state has been updated.

FadeLED_Func

FadeLED_Func(const byte pin, const uint32_t onTime, const uint32_t offTime, const bool invert = false)

The constructor creates an instance of a FadeLED_Func object, which in turn creates an instance of the FadeLED base class. The FadeLED_Func object inherits the read() and write() methods from the base class.

This class is used to create custom fade curves (output vs. time) besides the linear and exponential cases already supported by this library. Because an instance of the FadeLED_Func class can call FadeLED::read() to determine whether a fade cycle is in its turning-on or turning-off state, the code which converts the normalized output of an instance to the desired PWM level can generate non-symmetric fade curves, much like how FadeLED_Exp already functions.

NOTE: On some Arduino devices, such as the Arduino UNO, the LED_BUILTIN pin does not support PWM output.

Arguments

  • pin: const byte: PWM-capable GPIO pin which will drive an LED connected to it, or NO_PWM if output will be controlled outside the FadeLED_Func class rather than with a call to the class set() method.
  • onTime: const unsigned int: Time in milliseconds that GPIO pin takes to go from fully-off to fully-on.
  • offTime: const unsigned int: Time in milliseconds that GPIO pin takes to go from fully-on to fully-off.
  • invert: const bool: If false, the GPIO pin will be driven HIGH when the FadeLED object goes to its on state. If invert is true, the on state drives the GPIO pin LOW. The default is false (don't invert).

virtual bool update()

Checks if it is time to update the state of the FadeLED_Func object. This method should be called from within the Arduino sketch's loop() function.

Returns

  • bool: true if object's state has been updated.

double get() const

Gets normalized value which ramps linearly with time from 0.0 when the FadeLED_Func object is triggered, up to 1.0 until the on-time passes, then linearly back down to 0.0 until the off-time passes. The returned value is usually transformed by the application code to a new value between 0.0 and 1.0 which is then passed to method set().

Returns

  • double: Normalized value of linear ramp between 0.0 (fully off) and 1.0 (fully on).

void set(const double f)

Sets output level, usually paired with a transform function after a call to the get() method.

Arguments

  • f: const double: output level between 0.0 (fully off) and 1.0 (fully on).