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 #50 background imageLoading...
Page #50 background image
SunFounder ESP32 Starter Kit
When the code is successfully uploaded, the LEDs on the strip will sequentially turn on with a yellow color and then
turn off, creating a simple chasing effect.
How it works?
1. Include the Adafruit NeoPixel library: This line imports the Adafruit NeoPixel library so that the sketch can use
its functions and classes to control the LED strip.
#include <Adafruit_NeoPixel.h> // Include the Adafruit NeoPixel library
2. Define constants for the LED strip.
#define LED_PIN 13 // NeoPixel LED strip
#define NUM_LEDS 8 // Number of LEDs
3. Create an instance of the Adafruit_NeoPixel class.
// Create an instance of the Adafruit_NeoPixel class
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB +
˓NEO_KHZ800);
This line creates an instance of the Adafruit_NeoPixel class called strip and configures it with
the number of LEDs, the pin connected to the LED strip, and the signal parameters (GRB color order
and 800 kHz data rate).
Adafruit_NeoPixel (uint16_t n, int16_t p = 6, neoPixelType t = NEO_GRB +
NEO_KHZ800)
NeoPixel constructor when length, pin and pixel type are known at compile-time. Ruturn
Adafruit_NeoPixel object. Call the begin() function before use.
n: Number of NeoPixels in strand.
p: Arduino pin number which will drive the NeoPixel data in.
t: Pixel type - add together NEO_* constants defined in Adafruit_NeoPixel.h, for example
NEO_GRB+NEO_KHZ800 for NeoPixels expecting an 800 KHz (vs 400 KHz) data stream with color
bytes expressed in green, red, blue order per pixel.
4. Initialize the WS2812 RGB strip and sets the initial color of the strip to black (off).
void setup() {
strip.begin(); // Initialize the NeoPixel strip
strip.show(); // Set initial color to black
}
void begin (void): Configure NeoPixel pin for output.
void show (void): Transmit pixel data in RAM to NeoPixels.
5. In the loop() function, the LEDs on the strip will sequentially turn on with a yellow color and then turn off,
creating a simple chasing effect.
void loop() {
// Turn on LEDs one by one
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 100, 45, 0); // Set the color of the i-th LED to
˓red
strip.show(); // Update the LED strip with the new colors
(continues on next page)
44 Chapter 1. For Arduino User

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