Waveshare ESP32-C5-WIFI6-KIT-N16R8 to control onboard RGB LED using Adafruit_NeoPixel library, Arduino framework.

Exercise run on Waveshare ESP32-C5-WIFI6-KIT-N16R8 to control onboard RGB LED using Adafruit_NeoPixel library.



ESP32C5_RGB.ino
/*
Exercise run on Waveshare ESP32-C5-WIFI6-KIT-N16R8
to control onboard RGB LED using Adafruit_NeoPixel library.

The onboard RGB on Waveshare ESP32-C5-WIFI6-KIT-N16R8 is connected to GPIO27.

https://coxxect.blogspot.com/2026/02/waveshare-esp32-c5-wifi6-kit-n16r8-to.html
*/

#include <Adafruit_NeoPixel.h>

// Pin where the onboard RGB is connected
#define LED_PIN    27
// Number of LEDs (number of onboard RGB is 1)
#define LED_COUNT  1

// Create NeoPixel object
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);

void setup() {
  strip.begin();           // Initialize NeoPixel library
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Adjust brightness (0–255)
}

void loop() {

  // Cycle through Red, Green, Blue
  strip.setPixelColor(0, strip.Color(255, 0, 0)); // Red
  strip.show();
  delay(1000);

  strip.setPixelColor(0, strip.Color(0, 255, 0)); // Green
  strip.show();
  delay(1000);

  strip.setPixelColor(0, strip.Color(0, 0, 255)); // Blue
  strip.show();
  delay(1000);

  // Rainbow effect demo
  rainbowCycle(5);

}

// Simple rainbow cycle animation
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colors are a transition r->g->b->r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}



Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

Drive 320x240 ILI9341 SPI TFT using ESP32-S3 (NodeMCU ESP-S3-12K-Kit) using TFT_eSPI library, in Arduino Framework.