Pixel

Represents a single pixel of the Pimoroni Blinkt! board. In the context of blinkter, a pixel is a set of three LEDs that are associated together by the blinkt library.

This class contains most of the methods used in operating on individual pixels of the blinkt board. Most of the common features that users will wish to use are located in this class.

class blinkter.Pixel(board, addr)

Represents a single pixel on the BlinktBoard.

This class is the main point of interaction between the user and the blinkt board. Any operation done on a single pixel should be executed from an object of this class.

Users should not attempt to instantiate this class directly. Instead use the BlinktBoard.get_pixel() to acquire an instance of this class.

black()

Turns this pixel off completely.

Flashes this pixel repeatedly for the duration specified.

This method does not allow users to specify the ratio for which the pixel should be on to the time which it should be off. For this reason, using this method is not recommended. For more advanced blinking options, see start_blink() and stop_blink().

Like flash(), if no color parameters are specified, this method will flash between black and the current color.

Parameters:
  • r – Optional[int] The brightness to which the red LED should be set for this blink sequence.
  • g – Optional[int] The brightness to which the green LED should be set for this blink sequence.
  • b – Optional[int] The brightness to which the blue LED should be set for this blink sequence.
  • interval

    Optional[float] The time between switching between an “on” state and an “off” state.

    An “on” state is when the pixel’s color equals that specified in this method’s parameters.

    An “off” state is when the pixel’s color is anything except the color specified in this method’s parameters.

    NOTE: When the pixel is in an “off” state, it is not necessarily black. It is only not the specified color.

    The interval for both “on” and “off” states is equal. That is, the time spent “on” will always equal the time spent “off”.

    If this behavior is not ideal, see the methods start_blink() and stop_blink() for more advanced behavior.

  • duration – Optional[float] The length of time in seconds during which this blink sequence will run.
  • brightness

    Optional[float] Sets the overall brightness of the pixel when blinking.

    NOTE: If you set the brightness of the pixel using this option, the brightness set by this argument will remain even after the pixel has finished blinking.

    WARNING: This option does nothing in versions prior to version 1.0.0.

blue()

Changes the color of this pixel to blue.

decrement(led: blinkter.led.LED, amount=0, wrap_around=False)

Decreases the brightness of the specified LED by the specified amount.

Parameters:
  • ledLED specifies which LED should have its brightness decreased.
  • amount – Optional[int] The amount by which the specified LED should decreased.
  • wrap_around – Optional[boolean] Determines whether to set any values falling below zero to 255. Default is False. Default behavior prevents any value from causing the color brightness to fall below zero.
draw()

Sends this pixel’s internal state out to the GPIO, causing the pixel to light up.

Under normal circumstances, users should not have to call this method.

flash(r=0, g=0, b=0, length=0.25)

Causes this pixel to flash once.

If all of the color parameters (r, g, and b) Are zero, then sets this pixel to black and flashes the color that the pixel had been prior to calling this method.

The values of the color parameters must be between 0 and 255.

Parameters:
  • r – Optional[int] The brightness of the red LED to use in the flash.
  • g – Optional[int] The brightness of the red LED to use in the flash.
  • b – Optional[int] The brightness of the blue LED to use in the flash.
  • length

    Optional[float] The length of time in seconds over which the flash takes place.

    If the length parameter is omitted, it defaults to 0.25 (a quarter of a second).

green()

Changes the color of this pixel to green.

increment(led: blinkter.led.LED, amount=0, wrap_around=False)

Increments the selected LED’s brightness by the specified amount.

Parameters:
  • ledLED specifies which LED’s brightness should be incremented.
  • amount – Optional[int] The amount to increase the brightness of the specified LED.
  • wrap_around – Optional[boolean] Determines whether the pixel will set the color brightness to zero for any value that exceeds 255. The default is False. By default, increment() prevents color brightness from being invalid by setting the maximum at 255.
increment_brightness(amount=0.0)

Increments the overall brightness of this pixel by the specified amount. Similar to the increment() method, this method increases the brightness of the whole pixel by a specified scale factor.

Parameters:amount

Optional[float] The amount at which the brightness of this pixel will be increased.

Acceptable values are between -1.0 and 1.0.

If the brightness of the pixel drops below 0.05 the pixel will automatically turn off.

red()

Changes the color of this pixel to red.

revert_color()

Resets this pixel’s color to the most recently used color.

set_brightness(brightness)

Sets the total brightness of the pixel. Valid values are floats between 0.0 and 1.0.

Parameters:brightness – The value to which brightness is to be set.
set_color(r: int, g: int, b: int)

Sets the color of this pixel to the values specified.

The acceptable range for all of these parameters is between 0 and 255 inclusive.

Parameters:
  • r – int Specifies the brightness to which the red LED should be set.
  • g – int Specifies the brightness to which the green LED should be set.
  • b – int Specifies the brightness to which the blue LED should be set.
set_led(led: blinkter.led.LED, value: int)

Sets the specified LED to the specified brightness.

Parameters:
  • ledLED specifies which LED will have its brightness set.
  • value – int Specifies the level to which the brightness will be set. Acceptable values are between 0 and 255.

Starts a blink sequence. This sequence will not terminate until stop_blink() is called.

Unlike blink(), this method allows the user to specify the time which the pixel will be on and off separately.

Parameters:
  • r – Optional[int] The brightness to which the red LED will be set during this blink sequence.
  • g – Optional[int] The brightness to which the green LED will be set during this blink sequence.
  • b – Optional[int] The brightness to which the blue LED will be set during this blink sequence.
  • brightness

    Optional[int] The overall brightness of the whole pixel during this blink sequence.

    NOTE: Setting the brightness using this argument will carry over to the brightness that the pixel uses once it is finished blinking.

    WARNING: This option does nothing in versions prior to version 1.0.0.

  • on_length – Optional[float] The length of time in seconds that the pixel will be on for each flash.
  • off_length – Optional[float] The length of time in seconds that the pixel will be off between flashes.

Stops the running blink sequence if it was started using start_blink().

white()

Sets all three primary LEDs in this pixel to maximum levels to make this pixel appear white.