WS2812 light strip (modules.ws2812)

This module uses the I2S ofK210 to drive the module, so you need to pay attention to the conflict during the use

Currently supports up to 12 lights

1. Constructor

from modules import ws2812
class ws2812 (led_pin = -1, led_num = -1, i2s_num = I2S_DEVICE_2, i2s_chn = I2S_CHANNEL_3, i2s_dma_chn = DMAC_CHANNEL1)

Create a new ws2812 object by specifying parameters

1.1. Parameters

  • led_pin: The pin of the light strip data cable connection, such asboard_info.D [4]

  • led_num: How many lamp beads are there in the strip?

  • i2s_num: WhichI2S device is used to drive this object, the default is I2S_DEVICE_2, the value range is0-2

  • i2s_chn: WhichI2S channel is used by this object, the default is I2S_CHANNEL_3, and the value range is0-3

  • i2s_dma_chn: The DMA channel used by this object, generally not considered by users

2. Method

2.1. set_led

class_ws2812.set_led(num, color)

parameters

  • num: TheNth lamp, starting from 0

  • color: The color assigned to the lamp bead, of typetuple, (R, G, B)

return value

no

2.2. display

class_ws2812.display()

parameters

no

return value

no

3. Routine 0

from modules import ws2812
class_ws2812 = ws2812 (board_info.D [4], 30)
for i in range (30):
    class_ws2812.set_led (i, (0xff, 0,0))
class_ws2812.display ()

4. Routine 1

from modules import ws2812
class_ws2812 = ws2812 (board_info.D [4], 30)
r = 0
dir = True
while True:
    if dir:
        r + = 1
    else:
        r-= 1
    if r> = 255:
        r = 255
        dir = False
    elif r <0:
        r = 0
        dir = True
    for i in range (30):
        a = class_ws2812.set_led (i, (r, 0,0))
    a = class_ws2812.display ()

Above routine, see MaixPy_scripts

powered by GitbookFile Modify: 2020-11-25 18:03:47

results matching ""

    No results matching ""