Class: WS2801

WS2801

Represents your WS2801 led stripe

Constructor

new WS2801(options)

Creates the representation of the led stripe.
Parameters:
Name Type Description
options Object options for the led stripe representation
Properties
Name Type Description
count Number Number of led lights on the stripe (must be greater 0)
spiWrite WS2801~spiWrite Callback for writing to the SPI
rgbIndex Array [0] = index of red, [1] = index of green, [2] = index of blue; in the resulting data array for WS2801; default: [0] = 0, [1] = 1, [2] = 2; red first, green second, blue third
Source:

Members

count

Returns the number of supported led lights.
Source:

count

Sets the number of supported led lights.
Source:

Methods

clear() → {WS2801}

Sets all supported led lights to black.
Source:
Returns:
Type
WS2801

fill(…color) → {WS2801}

Sets all supported led lights to the given color.
Parameters:
Name Type Attributes Description
color String | Number | Array <repeatable>
Contains a string like "#fe12a9" or an array with red, green and blue as elements like [0xfe, 0x12, 0xa9] or a parameter list of three elments as red, green and blue like (..., 0xfe, 0x12, 0xa9)
Source:
Returns:
Type
WS2801
Example
//Usage
leds.fill("#ff0000") // set all led lights to red
leds.fill(0, 255, 0) // set all led lights to green
leds.fill([0x00, 0x00, 0xff]) // set all led lights to blue

setAll(colors) → {WS2801}

Set possibly all lights with given colors. If the number of given colors is to low, the rest goes black. Superfluous are ignored.
Parameters:
Name Type Description
colors Array.<(String|Array)>
Source:
Returns:
Type
WS2801

setLight(number, …color) → {WS2801}

Sets the color of the led light specified by the given index number.
Parameters:
Name Type Attributes Description
number Number Index of the led light, starting at 0. Must not exceed number of led lights.
color String | Number | Array <repeatable>
Contains a string like "#fe12a9" or an array with red, green and blue as elements like [0xfe, 0x12, 0xa9] or a parameter list of three elments as red, green and blue like (..., 0xfe, 0x12, 0xa9)
Source:
Returns:
Type
WS2801
Example
//Usage
leds.setLight(0, "#ff0000") //set first light to red
leds.setLight(1, 0, 255, 0) //set second light to green
leds.setLight(2, [0x00, 0x00, 0xff]) //set third light to blue

show() → {WS2801}

Writes the led lights colors to the led stripe using the supplied SPI instance. You have to call this method everytime you want to see the set colors on your led stripe.
Source:
Returns:
Type
WS2801

(static) rgbFrom(color) → {Array}

Static helper method to determine red, green and blue values. Either from a string like "#fe12a9" or from the elements of the array, where the elements are red, green and blue or from an array as once element, which is identical to the returning one. Usually this method will be called using a rest parameter. See setLight() or fill()
Parameters:
Name Type Description
color Array Having one element with a string or an array containing red, green and blue as elements or having three elements representing red, green and blue
Source:
Returns:
Contains red, green and blue as elements
Type
Array
Examples
//with String
let r, g, b
[r, g, b] = ws2801.rgbFrom(["#fe12a9"])
// r = 0xfe, g = 0x12, b = 0xa9
//with Elements
let r, g, b
[r, g, b] = ws2801.rgbFrom([0xfe, 0x12, 0xa9])
// r = 0xfe, g = 0x12, b = 0xa9
//with Array
let r, g, b
[r, g, b] = ws2801.rgbFrom([[0xfe, 0x12, 0xa9]])
// r = 0xfe, g = 0x12, b = 0xa9
//with rest parameter
function rgb(...color) {
   return ws2801.rgbFrom(color)
}
rgb("#fe12a9")
rgb(0xfe, 0x12, 0xa9)
rgb([0xfe, 0x12, 0xa9])

Type Definitions

spiWrite(data)

Callback for writing to the SPI
Parameters:
Name Type Description
data Array Data (color information) which has to be transfered to the led stripe
Source: