Smart Home Automation Forum
[arduino code examples for AS]-07 how to use WS2812B RGB LED by vertical direction - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KinCony AS (https://www.kincony.com/forum/forumdisplay.php?fid=64)
+--- Thread: [arduino code examples for AS]-07 how to use WS2812B RGB LED by vertical direction (/showthread.php?tid=6902)



[arduino code examples for AS]-07 how to use WS2812B RGB LED by vertical direction - admin - 10-22-2024

Code:
/*
  Made by KinCony IoT: https://www.kincony.com
  This code controls 1 WS2812 RGB LEDs connected to GPIO 16 on an ESP32-S3.
  Each LED will be set to blue with adjustable brightness.
  The Adafruit NeoPixel library is used to communicate with the WS2812 LEDs.

  Hardware setup:
  - WS2812 RGB LEDs are connected to GPIO 15 (data pin).
  - Total number of LEDs: 3.
*/

#include <Adafruit_NeoPixel.h>

// Create an instance of the Adafruit_NeoPixel class
// Parameters: number of LEDs (3), data pin (GPIO 15), LED type (NEO_GRB with 800 KHz communication)
Adafruit_NeoPixel rgb_display = Adafruit_NeoPixel(1, 16, NEO_GRB + NEO_KHZ800);

void setup() {
  // Initialize the NeoPixel library and prepare the LEDs for use
  rgb_display.begin();
}

void loop() {
  /*
    rgb_display.setPixelColor(uint16_t n, uint32_t c);
    This function sets the color of a specific LED.

    Parameters:
    - n: The LED number (starting from 0).
    - c: The color to set the LED to, in hexadecimal (0x0000ff = blue in RGB format).
  */

  // Set the first LED (LED 0) to blue
  rgb_display.setPixelColor(0, (0x0000ff)); // Blue color for the first LED (index 0)
  rgb_display.setBrightness(100);           // Set brightness to 100 out of 255
  rgb_display.show();                       // Update the LED to reflect the change

}
arduino ino file download:

.zip   LED_WS2812B-1pc.zip (Size: 834 bytes / Downloads: 23)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   LED_WS2812B-1pc.ino.merged.zip (Size: 179.91 KB / Downloads: 25)