pinpong example neopixel

Neopixel: WS2812 Light Strip

This Python code demonstrates how to control a WS2812 single-line RGB LED light strip. The Arduino main control board is connected to a Windows or Linux computer, and the WS2812 light strip is connected to the D9 port of the main control board.

# -*- coding: UTF-8 -*-
# Experiment effect: Control WS2812 single-line RGB LED light
# Connection: Connect an Arduino main control board to a Windows or Linux computer, connect the WS2812 light to the D9 port

import time
from pinpong.board import Board,Pin,NeoPixel # Import the NeoPixel class

Board("uno").begin()  # Initialization, select the board type (uno, leonardo, xugu) and port number. If no port number is entered, automatic recognition will be performed
#Board("uno","COM36").begin()  # Initialization by specifying the port under Windows
#Board("uno","/dev/ttyACM0").begin() # Initialization by specifying the port under Linux
#Board("uno","/dev/cu.usbmodem14101").begin()   # Initialization by specifying the port under Mac

NEOPIXEL_PIN = Pin(Pin.D9)
PIXELS_NUM = 4 # Number of lights

np = NeoPixel(NEOPIXEL_PIN,PIXELS_NUM)

while True:
    np[0] = (0, 255 ,0) # Set the RGB brightness of the first light
    np[1] = (255, 0, 0) # Set the RGB brightness of the second light
    np[2] = (0, 0, 255) # Set the RGB brightness of the third light
    np[3] = (255, 0, 255) # Set the RGB brightness of the fourth light
    print("color 1")
    time.sleep(1)
    np[1] = (0, 255, 0)
    np[2] = (255, 0, 0)
    np[3] = (255, 255, 0)
    np[0] = (0, 0, 255)
    print("color 2")
    time.sleep(1)