Treehopper C# API
LedShiftRegister Class Reference

Supports generic 8-bit or 16-bit LED shift register drivers, such as the STP16CPC26, CAT4016, TLC5916, etc More...

Inheritance diagram for LedShiftRegister:
ChainableShiftRegisterOutput ILedDriver IFlushable IFlushable

Public Types

enum  LedChannelCount { SixteenChannel = 16, EightChannel = 8 }
 The number of channels of this shift register More...
 

Public Member Functions

 LedShiftRegister (Spi SpiModule, SpiChipSelectPin LatchPin, LedChannelCount ChannelCount=LedChannelCount.SixteenChannel, DigitalOut OutputEnablePin=null, double speedMhz=6)
 Construct an LED shift register attached directly to a board SPI module More...
 
 LedShiftRegister (Spi SpiModule, SpiChipSelectPin LatchPin, Pwm OutputEnablePin, LedChannelCount ChannelCount=LedChannelCount.SixteenChannel, double speedMhz=6)
 Construct an LED shift register attached directly to a board SPI module More...
 
 LedShiftRegister (ChainableShiftRegisterOutput upstreamDevice, LedChannelCount ChannelCount=LedChannelCount.SixteenChannel, DigitalOut OutputEnablePin=null)
 Construct an LED shift register attached to the output of another shift register More...
 
 LedShiftRegister (ChainableShiftRegisterOutput upstreamDevice, Pwm OutputEnablePin, LedChannelCount ChannelCount=LedChannelCount.SixteenChannel)
 Construct an LED shift register attached to the output of another shift register More...
 
Task Clear ()
 Clear the display More...
 
async Task FlushAsync (bool force=false)
 Flush data to the port More...
 
async Task Write (byte[] value)
 Immediately update all the pins at once with the given value. More...
 

Protected Member Functions

override void updateFromCurrentValue ()
 Update the LED states from the current value More...
 
async Task FlushIfAutoFlushEnabled ()
 Classes extending this class should call this function after the internal pin data structure is updated. More...
 

Properties

double Brightness [get, set]
 Gets or sets the brightness of this driver More...
 
bool HasGlobalBrightnessControl [get]
 Gets whether this driver has global brightness More...
 
bool HasIndividualBrightnessControl [get]
 Gets whether this driver has individual brightness control. More...
 
IList< LedLeds = new Collection<Led>() [get]
 Gets the LEDs belonging to this controller More...
 
IList< ChainableShiftRegisterOutputChildren = new List<ChainableShiftRegisterOutput>() [get, set]
 
byte [] CurrentValue [get, protected set]
 The current value of the port More...
 
bool AutoFlush = true [get, set]
 Whether or not written data should automatically be flushed to the controller More...
 
IFlushable Parent [get, protected set]
 The parent shift register (if not null) this device is attached to More...
 

Detailed Description

Supports generic 8-bit or 16-bit LED shift register drivers, such as the STP16CPC26, CAT4016, TLC5916, etc

This driver provides support for many common 8-channel and 16-channel LED drivers that have an active-low Output Enable (OE) pin that supports global brightness control through PWMing. The following ICs are examples of drivers that are compatible with this library:

  • Texas Instruments TLC591x8-channel, up to 120 mA, 20V
  • Texas Instruments TLC592816-channel, up to 35 mA, 17V
  • Texas Instruments TLC5928x16-channel, up to 45 mA, 10V
  • Silicon Touch (SiTI) ST2221A8-channel, up to 90 mA, 9V
  • Silicon Touch (SiTI) ST2221C16-channel, up to 90 mA, 9V
  • Macroblock MBI502x16-channel, up to 90 mA, 17V
  • Allegro A628216-channel, up to 50 mA, 12V
  • ON Semiconductor CAT401616-channel, up to 100 mA, 5.5V
  • ST STP16C59616-channel, up to 120 mA, 16V
  • ST STP16CP0516-channel, up to 100 mA, 20V
  • ST STP16CPC2616-channel, up to 90 mA, 20V
  • ISSI IS31FL372616-channel, up to 60 mA, 4V
  • AMS AS112316-channel, up to 40 mA, 5.5V

Note that any other 8-bit or 16-bit shift register can also be used with this library if you want an Led-based interface to the shift register. For example, the low-cost (and ubiquitous) 74HC595 is perfectly capable of driving small indicator LEDs, and the TPIC6B595 could be used with this library to drive high-voltage, high-power LEDs (or nixie tubes, etc).

This library supports three different ways of working with the OE (output enable) pin:

  1. Unmanaged The library doesn't do anything with the OE pin. You can tie it to GND in your circuit, or control it outside the context of this library by yourself.
  2. GPIO pin If you pass a GPIO pin to the constructor, the library will be able to globally enable/disable the display through the Brightness property. Setting a brightness of 0.5 or greater will turn on the display, otherwise, the display will be off.
  3. PWM pin If you pass a PWM pin to the constructor, the library will be able to control the global brightness of the display. Note that CIE perceptual brightness conversion will be performed, so, i.e., setting Brightness to 0.5 will produce a result that appears half as bright as a Brightness of 1.0.

Member Enumeration Documentation

◆ LedChannelCount

enum LedChannelCount
strong

The number of channels of this shift register

Enumerator
SixteenChannel 

A 16-channel LED shift register

EightChannel 

An 8-channel LED shift register

Constructor & Destructor Documentation

◆ LedShiftRegister() [1/4]

LedShiftRegister ( Spi  SpiModule,
SpiChipSelectPin  LatchPin,
LedChannelCount  ChannelCount = LedChannelCount.SixteenChannel,
DigitalOut  OutputEnablePin = null,
double  speedMhz = 6 
)

Construct an LED shift register attached directly to a board SPI module

Parameters
SpiModuleThe board's SPI module
LatchPinThe pin to use for latches
ChannelCountWhether the driver is 16 or 8-channel
OutputEnablePinThe output enable pin, if any, to use.
speedMhzThe speed, in MHz, to use when communicating

◆ LedShiftRegister() [2/4]

LedShiftRegister ( Spi  SpiModule,
SpiChipSelectPin  LatchPin,
Pwm  OutputEnablePin,
LedChannelCount  ChannelCount = LedChannelCount.SixteenChannel,
double  speedMhz = 6 
)

Construct an LED shift register attached directly to a board SPI module

Parameters
SpiModuleThe board's SPI module
LatchPinThe pin to use for latches
OutputEnablePinThe PWM pin to use, allowing controllable global brightness.
ChannelCountThe number of channels this LED shift register has
speedMhzThe speed, in MHz, to use when communicating

◆ LedShiftRegister() [3/4]

LedShiftRegister ( ChainableShiftRegisterOutput  upstreamDevice,
LedChannelCount  ChannelCount = LedChannelCount.SixteenChannel,
DigitalOut  OutputEnablePin = null 
)

Construct an LED shift register attached to the output of another shift register

Parameters
upstreamDeviceThe upstream device this shift register is attached to
OutputEnablePinThe digital pin to use, if any, to control the display state
ChannelCountThe number of channels this LED shift register has

◆ LedShiftRegister() [4/4]

LedShiftRegister ( ChainableShiftRegisterOutput  upstreamDevice,
Pwm  OutputEnablePin,
LedChannelCount  ChannelCount = LedChannelCount.SixteenChannel 
)

Construct an LED shift register attached to the output of another shift register

Parameters
upstreamDeviceThe upstream device this shift register is attached to
OutputEnablePinThe PWM pin to use, if any, to control the display brightness
ChannelCountThe number of channels this LED shift register has

Member Function Documentation

◆ Clear()

Task Clear ( )

Clear the display

Returns
An awaitable task that completes when finished

Implements ILedDriver.

◆ updateFromCurrentValue()

override void updateFromCurrentValue ( )
protectedvirtual

Update the LED states from the current value

Implements ChainableShiftRegisterOutput.

◆ FlushAsync()

async Task FlushAsync ( bool  force = false)
inherited

Flush data to the port

Parameters
forceWhether to flush all data to the port, even if it doesn't appear to have changed.
Returns
An awaitable task that completes when finished

Implements IFlushable.

◆ Write()

async Task Write ( byte []  value)
inherited

Immediately update all the pins at once with the given value.

Flush() will be implicity called.

Parameters
valueA value representing the data to write to the port
Returns
An awaitable task that completes upon successfully writing the value.

◆ FlushIfAutoFlushEnabled()

async Task FlushIfAutoFlushEnabled ( )
protectedinherited

Classes extending this class should call this function after the internal pin data structure is updated.

Returns

Property Documentation

◆ Brightness

double Brightness
getset

Gets or sets the brightness of this driver

◆ HasGlobalBrightnessControl

bool HasGlobalBrightnessControl
get

Gets whether this driver has global brightness

The state of this value depends if the board was constructed with a Pwm pin or not.

◆ HasIndividualBrightnessControl

bool HasIndividualBrightnessControl
get

Gets whether this driver has individual brightness control.

This parameter will always return false.

◆ Leds

IList<Led> Leds = new Collection<Led>()
get

Gets the LEDs belonging to this controller

◆ Children

IList<ChainableShiftRegisterOutput> Children = new List<ChainableShiftRegisterOutput>()
getsetinherited

◆ CurrentValue

byte [] CurrentValue
getprotected setinherited

The current value of the port

◆ AutoFlush

bool AutoFlush = true
getsetinherited

Whether or not written data should automatically be flushed to the controller

◆ Parent

IFlushable Parent
getprotected setinherited

The parent shift register (if not null) this device is attached to


The documentation for this class was generated from the following file: