Exemple #1
0
 def __init__(self,
              leds=[32, 8],
              pin=18,
              channel=0,
              freq_hz=800000,
              dma=5,
              invert=False,
              brightness=255,
              type_=ws.WS2811_STRIP_GRB):
     self._leds = ws.new_ws2811_t()
     for cn in range(2):
         c = ws.ws2811_channel_get(self._leds, cn)
         ws.ws2811_channel_t_count_set(c, 0)
         ws.ws2811_channel_t_gpionum_set(c, 0)
         ws.ws2811_channel_t_invert_set(c, 0)
         ws.ws2811_channel_t_brightness_set(c, 0)
     self._ch = ws.ws2811_channel_get(self._leds, channel)
     ws.ws2811_channel_t_count_set(self._ch, leds[0] * leds[1])
     ws.ws2811_channel_t_gpionum_set(self._ch, pin)
     ws.ws2811_channel_t_invert_set(self._ch, (0 if invert == False else 1))
     ws.ws2811_channel_t_brightness_set(self._ch, brightness)
     ws.ws2811_channel_t_strip_type_set(self._ch, type_)
     ws.ws2811_t_freq_set(self._leds, freq_hz)
     ws.ws2811_t_dmanum_set(self._leds, dma)
     self.data = LED_Data(self._ch, leds)
     atexit.register(self._c)
     r = ws.ws2811_init(self._leds)
     if (r != ws.WS2811_SUCCESS):
         raise RuntimeError(ws.ws2811_get_return_t_str(r))
    def __init__(self,
                 num,
                 pin,
                 freq_hz=800000,
                 dma=10,
                 invert=False,
                 brightness=255,
                 channel=0,
                 strip_type=ws.WS2811_STRIP_RGB):
        """Class to represent a NeoPixel/WS281x LED display.  Num should be the
        number of pixels in the display, and pin should be the GPIO pin connected
        to the display signal line (must be a PWM pin like 18!).  Optional
        parameters are freq, the frequency of the display signal in hertz (default
        800khz), dma, the DMA channel to use (default 10), invert, a boolean
        specifying if the signal line should be inverted (default False), and
        channel, the PWM channel to use (defaults to 0).
        """
        # Create ws2811_t structure and fill in parameters.
        self._leds = ws.new_ws2811_t()

        # Initialize the channels to zero
        for channum in range(2):
            chan = ws.ws2811_channel_get(self._leds, channum)
            ws.ws2811_channel_t_count_set(chan, 0)
            ws.ws2811_channel_t_gpionum_set(chan, 0)
            ws.ws2811_channel_t_invert_set(chan, 0)
            ws.ws2811_channel_t_brightness_set(chan, 0)

        # Initialize the channel in use
        self._channel = ws.ws2811_channel_get(self._leds, channel)
        ws.ws2811_channel_t_count_set(self._channel, num)
        ws.ws2811_channel_t_gpionum_set(self._channel, pin)
        ws.ws2811_channel_t_invert_set(self._channel, 0 if not invert else 1)
        ws.ws2811_channel_t_brightness_set(self._channel, brightness)
        ws.ws2811_channel_t_strip_type_set(self._channel, strip_type)

        # Initialize the controller
        ws.ws2811_t_freq_set(self._leds, freq_hz)
        ws.ws2811_t_dmanum_set(self._leds, dma)

        # Grab the led data array.
        self._led_data = _LED_Data(self._channel, num)

        # Substitute for __del__, traps an exit condition and cleans up properly
        atexit.register(self._cleanup)