MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / __init__

Method __init__

mpython/lib/optional/ws2812.py:31–53  ·  view source on GitHub ↗

Params: * spi_bus = SPI bus ID (1 or 2) * led_count = count of LEDs * intensity = light intensity (float up to 1)

(self, spi_bus=1, led_count=1, intensity=1)

Source from the content-addressed store, hash-verified

29 buf_bytes = (0x88, 0x8e, 0xe8, 0xee)
30
31 def __init__(self, spi_bus=1, led_count=1, intensity=1):
32 """
33 Params:
34 * spi_bus = SPI bus ID (1 or 2)
35 * led_count = count of LEDs
36 * intensity = light intensity (float up to 1)
37 """
38 self.led_count = led_count
39 self.intensity = intensity
40 self._rgblist = [(0,0,0)]*self.led_count
41
42 # prepare SPI data buffer (4 bytes for each color)
43 self.buf_length = self.led_count * 3 * 4
44 self.buf = bytearray(self.buf_length)
45
46 # SPI init
47 try:
48 self.spi = pyb.SPI(spi_bus, pyb.SPI.MASTER, baudrate=3200000, polarity=0, phase=1)
49 except:
50 self.spi = pyb.SPI(spi_bus, baudrate=3200000, polarity=0, phase=1)
51
52 # turn LEDs off
53 self.show([])
54
55 def __len__(self):
56 return self.led_count

Callers

nothing calls this directly

Calls 2

showMethod · 0.95
SPIMethod · 0.80

Tested by

no test coverage detected