![]() |
Serial Wombat Arduino Library
|
A Class representing a WS2812 or compatible RGB LED string connected to a Serial Wombat pin. More...
#include <SerialWombatWS2812.h>
Public Member Functions | |
SerialWombatWS2812 (SerialWombatChip &serialWombat) | |
Constructor for SerialWombatWS2812 class. More... | |
int16_t | begin (uint8_t pin, uint8_t numberOfLEDs, uint16_t userBufferIndex) |
Initialize a WS2812 LED driver object. More... | |
int16_t | write (uint8_t led, uint32_t color) |
Set an LED color. More... | |
int16_t | write (uint8_t led, int16_t color) |
An overload for Write in case write(x,0); is interpreted as an int16_t rather than uint32_t. More... | |
int16_t | write (uint8_t led, int32_t color) |
An overload for Write in case write(x,0); is interpreted as an int32_t rather than uint32_t. More... | |
int16_t | write (uint8_t led, uint8_t length, uint32_t colors[]) |
Set a number of LEDs to colors based on an array of uint32_t colors. More... | |
int16_t | writeAnimationLED (uint8_t frame, uint8_t led, uint32_t color) |
set the color of one LED in an animation frame More... | |
int16_t | writeAnimationLED (uint8_t frame, uint8_t led, int16_t color) |
An overload color is interpreted as an int16_t rather than uint32_t. More... | |
int16_t | writeAnimationLED (uint8_t frame, uint8_t led, int32_t color) |
An overload color is interpreted as an int32_t rather than uint32_t. More... | |
int16_t | writeAnimationFrame (uint8_t frame, uint32_t colors[]) |
Store an array of colors for an entire animation frame. More... | |
int16_t | writeAnimationFrameDelay (uint8_t frame, uint16_t delay_mS) |
Set how long an animation frame should be displayed before moving to the next frame. More... | |
int16_t | writeAnimationUserBufferIndex (uint16_t index, uint8_t numberOfFrames) |
set the location in UserBuffer where the animation array will be stored and number of frames More... | |
int16_t | readBufferSize () |
returns the number of bytes of UserBuffer required to service the configured number of LEDs More... | |
int16_t | writeMode (SWWS2812Mode mode) |
Sets the mode of the WS2812 LED Driver. More... | |
int16_t | barGraph (uint8_t sourcePin, uint32_t offRGB, uint32_t onRGB, uint16_t min, uint16_t max) |
Display a bargraph using the configured ws2812 class. More... | |
![]() | |
SerialWombatPin (SerialWombatChip &serialWombatChip) | |
Instantiates a Serial Wombat Pin. More... | |
SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin) | |
Instantiates a Serial Wombat Pin. More... | |
uint16_t | readPublicData () |
Read the 16 Bit public data associated with this pin. More... | |
void | pinMode (uint8_t mode) |
Set pin to INPUT or OUTPUT. More... | |
void | pinMode (uint8_t mode, bool pullDown, bool openDrain) |
Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More... | |
void | digitalWrite (uint8_t val) |
Set output pin High or Low. More... | |
int | digitalRead () |
Reads the state of the Pin. More... | |
uint16_t | writePublicData (uint16_t value) |
Write a 16 bit value to this pin. More... | |
uint8_t | pin () |
Returns the current SW pin number. Used primarily for virtual calls by derived classes. More... | |
uint8_t | swPinModeNumber () |
Returns the Mode number. Used primarily by derived classes to populate packet data. More... | |
Additional Inherited Members | |
![]() | |
uint8_t | _pin = 255 |
SerialWombatChip & | _sw |
uint8_t | _pinMode = 0 |
A Class representing a WS2812 or compatible RGB LED string connected to a Serial Wombat pin.
This class is only supported on the Serial Wombat SW18AB chip. It is not supported on the Serial Wombat 4X line. This pin mode can only be used on enhanced capability pins (WP0-4, WP7, or WP9-19)
This class controls a State Machine driven driver for a WS2812 compatible RGB LED string.
Each instance of this class uses an average of approximately TBD% of the SW18's processing time. This varies by configuration options and usage.
The Serial Wombat WS2812 driver can be configured in a number of ways:
See the available examples in the Arduino Library for usage.
The Serial Wombat WS2812 driver is extremely efficient in terms of processor time since it uses the PIC24FJ256GA702's DMA and SPI hardware to generate the WS2812 signal. This allows the Serial Wombat firmware to easily clock out WS2812 signals while doing other thigns. However, this method is very RAM intensive, requiring about 50 bytes of ram for each LED.
The RAM used for buffering this signal is stored in the User Buffer RAM, an array available for the user to allocate to various PIN modes' uses. In Version 2.0.3 of the Serial Wombat 18AB firmware there is 8k of RAM allocated to User Buffer, allowing about 160 LEDs to be used if all RAM is allocated to the WS2812.
A number of frames to be shown in rotation with configurable delays inbetween can also be stored in the User Buffer. This is in additional to the rendering buffer. Each animation frame requires 2+3*NumberOfLEDs bytes.
The Update rate is variable with the number of LEDs so that rendering of colors into the User Buffer is spread across multiple Serial Wombat 1mS execution frames. The LEDs will be updated approximately every X mS, where X is the number of LEDs plus 20.
A tutorial is available here:
/// ///
SerialWombatWS2812::SerialWombatWS2812 | ( | SerialWombatChip & | serialWombat | ) |
Constructor for SerialWombatWS2812 class.
serialWombat | SerialWombat chip on which the driver will run |
int16_t SerialWombatWS2812::barGraph | ( | uint8_t | sourcePin, |
uint32_t | offRGB, | ||
uint32_t | onRGB, | ||
uint16_t | min, | ||
uint16_t | max | ||
) |
Display a bargraph using the configured ws2812 class.
sourcePin | The data source to use for the bargraph |
offRGB | The color to use for LEDs beyond the bargraph level |
onRGB | The color to use for LEDs lit by the bargraph |
min | The public data value (or below) to be treated as the beginning of the bargraph |
max | The public data value (or above) to be treated as the end of the bargraph |
int16_t SerialWombatWS2812::begin | ( | uint8_t | pin, |
uint8_t | numberOfLEDs, | ||
uint16_t | userBufferIndex | ||
) |
Initialize a WS2812 LED driver object.
This function initializes hardware and data arrays for the WS2812 driver. It requires about 30uS per LED to initialize the data array. During this time pin processing is suspended. This can cause glitches in other pins. It is recommended that this pin mode be initialized once near the beginning of at power up and that begin() not be called during real-time operation.
pin | The pin connected to the WS2812. This must be an enhanced capability pin ( WP0-4, WP7, or WP9-19) |
numberOfLEDs | The number of LEDs connected in series to the pin |
userBufferIndex | The index in bytes into the User Buffer area where the signal train to be sent to the LEDs is stored. The amount of data bytes required for the configured number of LEDs can be queried with readBufferSize. This area must not be used by other pins, and cannot extend past the end of the 8k of space. |
int16_t SerialWombatWS2812::readBufferSize | ( | ) |
returns the number of bytes of UserBuffer required to service the configured number of LEDs
This number does not include any animation frames.
int16_t SerialWombatWS2812::write | ( | uint8_t | led, |
int16_t | color | ||
) |
An overload for Write in case write(x,0); is interpreted as an int16_t rather than uint32_t.
int16_t SerialWombatWS2812::write | ( | uint8_t | led, |
int32_t | color | ||
) |
An overload for Write in case write(x,0); is interpreted as an int32_t rather than uint32_t.
int16_t SerialWombatWS2812::write | ( | uint8_t | led, |
uint32_t | color | ||
) |
Set an LED color.
led | The index of the LED to be set to color |
color | The color of the LED in 0x00RRGGBB format |
int16_t SerialWombatWS2812::write | ( | uint8_t | led, |
uint8_t | length, | ||
uint32_t | colors[] | ||
) |
Set a number of LEDs to colors based on an array of uint32_t colors.
led | The index of the first led to set |
length | The number of LEDs to set, and the number of entires in colors array |
An | array of uint32_t integer colors in the format 0x00RRGGBB format |
int16_t SerialWombatWS2812::writeAnimationFrame | ( | uint8_t | frame, |
uint32_t | colors[] | ||
) |
Store an array of colors for an entire animation frame.
frame | The index of the frame being stored |
colors | an array of uint32_t colors in 0x00RRGGBB format to be stored in the frame. The length of the array must match the number of LEDs |
int16_t SerialWombatWS2812::writeAnimationFrameDelay | ( | uint8_t | frame, |
uint16_t | delay_mS | ||
) |
Set how long an animation frame should be displayed before moving to the next frame.
frame | The index of the frame being set |
dealy_mS | the amount of time to display the frame in mS |
int16_t SerialWombatWS2812::writeAnimationLED | ( | uint8_t | frame, |
uint8_t | led, | ||
int16_t | color | ||
) |
An overload color is interpreted as an int16_t rather than uint32_t.
int16_t SerialWombatWS2812::writeAnimationLED | ( | uint8_t | frame, |
uint8_t | led, | ||
int32_t | color | ||
) |
An overload color is interpreted as an int32_t rather than uint32_t.
int16_t SerialWombatWS2812::writeAnimationLED | ( | uint8_t | frame, |
uint8_t | led, | ||
uint32_t | color | ||
) |
set the color of one LED in an animation frame
frame | The Frame index of the color being set |
led | The LED index in that frame of the color being set |
color | The color of the LED in 0x00RRGGBB format |
int16_t SerialWombatWS2812::writeAnimationUserBufferIndex | ( | uint16_t | index, |
uint8_t | numberOfFrames | ||
) |
set the location in UserBuffer where the animation array will be stored and number of frames
index | The index into UserBuffer |
numberOfFrames | The number of frames that make up the animation |
int16_t SerialWombatWS2812::writeMode | ( | SWWS2812Mode | mode | ) |
Sets the mode of the WS2812 LED Driver.