EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #341 background imageLoading...
Page #341 background image
SunFounder ESP32 Starter Kit
from neopixel import NeoPixel
2. Use the NeoPixel class from the neopixel module to initialize the pixels object, specifying the data pin and
the number of LEDs.
pixels = NeoPixel(pin, 8) # create NeoPixel driver on pin for 8 pixels
3. Set the color of each LED and use the write() method to send the data to the WS2812 LED to update its display.
pixels[0] = [64,154,227] # set the pixel
pixels[1] = [128,0,128]
pixels[2] = [50,150,50]
pixels[3] = [255,30,30]
pixels[4] = [0,128,255]
pixels[5] = [99,199,0]
pixels[6] = [128,128,128]
pixels[7] = [255,100,0]
pixels.write() # write data to all pixels
Learn More
We can randomly generate colors and make a colorful flowing light.
Note:
Open the 2.7_rgb_strip_random.py file located in the esp32-starter-kit-main\micropython\codes
path, or copy and paste the code into Thonny. Then, click “Run Current Script” or press F5 to execute it. * Make
sure to select the “MicroPython (ESP32).COMxx” interpreter in the bottom right corner.
from machine import Pin
import neopixel
import time
import random
# Set the number of pixels for the running light
num_pixels = 8
# Set the data pin for the RGB LED strip
data_pin = Pin(14, Pin.OUT)
# Initialize the RGB LED strip object
pixels = neopixel.NeoPixel(data_pin, num_pixels)
# Continuously loop the running light
while True:
for i in range(num_pixels):
# Generate a random color for the current pixel
color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
# Turn on the current pixel with the random color
pixels[i] = color
(continues on next page)
3.13. 2.7 RGB LED Strip 335

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish