Ejemplo n.º 1
0
def test_contrast():
    device = apa102(serial, cascaded=6)
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="red")
    serial.reset_mock()
    device.contrast(0x6B)
    serial.data.assert_called_with(
        padding(6) + [0xE6, 0, 0, 0xFF] * 6 + padding(6))
Ejemplo n.º 2
0
def test_display():
    device = apa102(serial, width=4, height=1)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=(0x11, 0x22, 0x33, 0x44))

    serial.data.assert_called_with(
        padding(4) + [0xE4, 0x33, 0x22, 0x11] * 4 + padding(4))
    def __init__(self, num_leds, port=0, device=0, bus_speed_hz=2000000):
        """
        Constructor
        """

        self.num_leds = num_leds  # Number of LED's in your APA102 LED Strip.

        # Initialise serial using Hardware SPI0 (SCLK=BCM 11, MOSI/SDA=BCM 10).
        # Default bus_speed_hz=8000000. This value may need to be lowered
        # if your Logic Level Converter cannot switch fast enough.
        # Allowed vales are 500000 ,1000000, 2000000, 4000000, 8000000, 16000000, 32000000
        # For find the spi class at https://github.com/rm-hull/luma.core/blob/master/luma/core/interface/serial.py
        self.serial = spi(port=port, device=device, bus_speed_hz=bus_speed_hz)

        # Initialise serial using "Big Banging" SPI technique on general GPIO Pins.
        # For find the bitbang class at https://github.com/rm-hull/luma.core/blob/master/luma/core/interface/serial.py
        # self.serial = bitbang(SCLK=13, SDA=6)

        # Color buffer "array", initialised to all black.
        # The color values in this buffer are applied to the APA102 LED Strip
        # by the update() function. The value at position 0 = the LED first LED
        # in the strip.
        self.color_buffer = deque([None] * self.num_leds, maxlen=self.num_leds)

        # Initialise APA102 device instance using serial instance created above.
        self.device = apa102(serial_interface=self.serial,
                             cascaded=self.num_leds)

        # Reset device and set it's global contrast level.
        self.clear()
        self.set_contrast(128)
        self._last_contrast = 0  # Used in _blink()
        self._blink_buffer = None  # used in _blink()
        self._blink_index = 0  # used in _blink()

        self._thread = None
        self.mode = APA102.MODE_NOT_ANIMATING

        self.animation_speed = 5  #see set_animation_speed()
        self.animation_delay_secs = 0.5  #see set_animation_speed()
Ejemplo n.º 4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017 Richard Hull and contributors
# See LICENSE.rst for details.
#
# Based on https://github.com/pimoroni/blinkt/blob/master/examples/larson_hue.py

import math
import time
import colorsys

from luma.led_matrix.device import apa102
from luma.core.render import canvas

device = apa102(width=8, height=1)

FALLOFF = 1.9
SCAN_SPEED = 4


def main():

    start_time = time.time()

    while True:
        delta = (time.time() - start_time)

        # Offset is a sine wave derived from the time delta
        # we use this to animate both the hue and larson scan
        # so they are kept in sync with each other
        offset = (math.sin(delta * SCAN_SPEED) + 1) / 2
Ejemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.

import time

from luma.led_matrix.device import apa102
from luma.core.render import canvas

device = apa102(width=8, height=1)


def rotate(l):
    return l[-1:] + l[:-1]


def main():
    colors = [
        "red",
        "orange",
        "yellow",
        "green",
        "blue",
        "indigo",
        "violet",
        "white"
    ]

    for color in colors:
        with canvas(device) as draw:
Ejemplo n.º 6
0
# in the strip.
color_buffer = deque(['black'] * NUM_LEDS, maxlen=NUM_LEDS)  # (3)

# Initialise serial using Hardware SPI0 (SCLK=BCM 11, MOSI/SDA=BCM 10).
# Default bus_speed_hz=8000000. This value may need to be lowered
# if your Logic Level Converter cannot switch fast enough.
# Allowed values are 500000, 1000000, 2000000, 4000000, 8000000, 16000000, 32000000
# For find the spi class at https://github.com/rm-hull/luma.core/blob/master/luma/core/interface/serial.py
serial = spi(port=0, device=0, bus_speed_hz=2000000)  # (4)

# Initialise serial using "Big Banging" SPI technique on general GPIO Pins.
# For find the bitbang class at https://github.com/rm-hull/luma.core/blob/master/luma/core/interface/serial.py
# serial = bitbang(SCLK=13, SDA=6)                                                     # (5)

#Initialise APA102 device instance using serial instance created above.
device = apa102(serial_interface=serial, cascaded=NUM_LEDS)  # (6)

# Reset device and set it's global contrast level.
device.clear()  # (7)
contrast_level = 128  # 0 (off) to 255 (maximum brightness)
device.contrast(contrast_level)


def set_color(color='black', index=-1):  # (8)
    """
    Set the color of single LED (index >= 0), or all LEDs (when index == -1)
    """
    if index == -1:
        global color_buffer
        color_buffer = deque([color] * NUM_LEDS, maxlen=NUM_LEDS)
    else:
Ejemplo n.º 7
0
def test_show():
    device = apa102(serial, cascaded=5)
    serial.reset_mock()
    device.show()
    serial.data.assert_not_called()
Ejemplo n.º 8
0
def test_init_cascaded():
    device = apa102(serial, cascaded=7)
    assert device.width == 7
    assert device.height == 1
    serial.data.assert_called_with(
        padding(7) + [0xE0, 0, 0, 0] * 7 + padding(7))