Skip to content

Library methods documentation

Blaž Rolih edited this page Mar 31, 2024 · 5 revisions

All following examples use variable strip which is a Neopixel class object. More about it can be found here.

In order for changes to have an effect, you need to call strip.show() after any change. For more details see description of show below.


brightness(brightness=None)

Parameter brightness: [default: None] Value of brightness on interval 1..255.

  • If brightness is None, returns current brightness value. Otherwise set brightness to passed value, which is clipped to interval 1..255.

Example:

strip.brightness(42)

set_pixel_line_gradient(pixel1, pixel2, left_rgb_w, right_rgb_w, how_bright=None)

Parameter pixel1: Index of starting pixel (inclusive).

Parameter pixel2: Index of ending pixel (inclusive).

Parameter left_rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing starting color.

Parameter right_rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing ending color.

Parameter how_bright: [default: None] Brightness of current interval. If how_bright is None, use global brightness value.

  • Create gradient (transition in color from left_rgb_w to right_rgb_w) between leds with index pixel1 and index pixel2 (inclusive).

Example:

rgbw1 = (0, 0, 50, 0)
rgbw2 = (50, 0, 0, 250)
strip.set_pixel_line_gradient(0, 42, rgbw1, rgbw2)

set_pixel_line(pixel1, pixel2, rgb_w, how_bright=None)

Parameter pixel1: Index of starting pixel (inclusive).

Parameter pixel2: Index of ending pixel (inclusive).

Parameter rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing color to be used.

Parameter how_bright: [default: None] Brightness of current interval. If how_bright is None, use global brightness value.

  • Fill leds from led with index pixel1 to index pixel2 (inclusive) with color rgb_w.

Example:

rgb = (0, 0, 50)
strip.set_pixel_line(0, 42, rgb)

set_pixel(pixel_num, rgb_w, how_bright=None)

Parameter pixel_num: Index of pixel to be set or slice object representing multiple leds.

Parameter rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing color to be used.

Parameter how_bright: [default: None] Brightness of current interval. If how_bright is None, use global brightness value.

  • Set pixel on index pixel_num to color rgb_w. If pixel_num is slice object the operation is applied to all pixels implied by the slice

Example:

strip.set_pixel(42, (0, 0, 92))

get_pixel(pixel_num):

Parameter pixel_num: Index of pixel of which colors will be returned

  • return tuple of form (r, g, b) or (r, g, b, w) representing color of pixel on index <pixel_num>

Example:

color = strip.get_pixel(0)
color[0] = 42
strip.fill(color)

__setitem__(idx, rgb_w)

Parameter idx: Index can either be indexing number or slice (see examples).

Parameter rgb_w: Tuple (or list of tuples) of form (r, g, b) or (r, g, b, w) representing color to be used.

  • Set pixel or pixels represented by idx to color rgb_w.

Examples:

strip[10] = (0,255,0)             # <- sets #10 to green
strip[15:21] = (255,0,0)          # <- sets 16,17 .. 20 to red
strip[21:29:2] = (0,0,255)        # <- sets 21,23,25,27 to blue
strip[1::2] = (0,0,0)             # <- sets all odd pixels to 'off'
strip[40:42] = [(0,5,0), (0,5,0)] # <- replaces all pixels with those from the array (make sure the lengths match!)

colorHSV(hue, sat, val)

Parameter hue: Hue component. Should be on interval 0..65535.

Parameter sat: Saturation component. Should be on interval 0..255.

Parameter val: Value component. Should be on interval 0..255.

Example:

color = strip.colorHSV(32000, 255, 200)
strip.fill(color)

rotate_left(num_of_pixels=None)

Parameter: [default: None] Number of pixels to be shifted to the left. If num_of_pixels is None, it shifts for 1.

  • Shift all pixels in circular fashion to the left with step of size num_of_pixels.

Example:

strip.rotate_left(1) # [1, 2, 3] becomes [2, 3, 1]

rotate_right(num_of_pixels=None)

Parameter: [default: None] Number of pixels to be shifted to the right. If num_of_pixels is None, it shifts for 1.

  • Shift all pixels in circular fashion to the right with step of size num_of_pixels.

Example:

strip.rotate_right(1) # [1, 2, 3] becomes [3, 1, 2]

show()

  • Send data to led-strip, making all changes on leds have an effect. This method should be used after every method that changes the state of leds or after a chain of changes.

Example:

strip.rotate_right(1)
strip.set_pixel(0, (0, 50, 0))
strip.show()

fill(self, rgb_w, how_bright=None)

Parameter rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing color to be used.

Parameter how_bright: [default: None] Brightness of current interval. If how_bright is None, use global brightness value.

  • Fill the entire strip with color rgb_w.

Example:

strip.fill((0, 50, 0))

clear()

  • Clear the entire strip, i.e. set every led color to 0.

Example:

strip.clear()