Tutorial

Table Of Contents
63
The above code will control all WS2812 lights to cycle through the three colors, press CTRL+C to exit
the program.
If you want to control the color of a single lamp, you can use the following code, where i is the serial
number of the lamp, the serial number of the first lamp connected from the driver board is 0, and the second
lamp is 1. By analogy, R, G, B are the brightness of the corresponding three color channels:
LED.strip.setPixelColor(i, Color(R, G, B))
LED.strip.show()
Instantiate the object and execute the method function. The function colorWipe () needs to pass in three
parameters, namely R, G, and B, which correspond to the brightness of the three primary colors of red, green,
and blue. The value range is 0- 255, the larger the value, the higher the brightness of the corresponding color
channel. If the values of the three color channels are the same, white light is emitted. Specific examples are as
follows:
if __name__ == '__main__':
LED = LED()
try:
while 1:
LED.colorWipe(255, 0, 0) # All the lights turn red
time.sleep(1)
LED.colorWipe(0, 255, 0) # All lights turn green
time.sleep(1)
LED.colorWipe(0, 0, 255) # All lights turn blue
time.sleep(1)
except:
LED.colorWipe(Color(0,0,0)) # Turn off all lights
Note: You must use the Color () method to pack the RGB values and then pass them to setPixelColor ()