Built-in project · ESP32-C6-DevKitC-1
ESP32-C6 rainbow
A hue wheel on the DevKitC-1's own RGB LED and seven more, bit-banged on GPIO 8. The whole build, an ESP32-C6 and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Runs in your browser. Free, and no account needed.
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
sketch.ino · ESP32-C6-DevKitC-1
// Rainbow: the DevKitC-1's own RGB LED, and a strip beside it.
//
// GPIO 8 on this board is not a plain LED. It is an addressable one (a
// WS2812 in the corner by the USB socket), and it wants twenty-four bits, not
// a level. That is the pin `LED_BUILTIN` names, so this is what the board's
// LED is actually for.
//
// Wiring, strip to board:
// DIN -> GPIO 8 VDD -> 5 V VSS -> GND
//
// One wire carries the whole chain: the board's own LED first, then anything
// wired after it. There is no clock: a bit is a high pulse whose length is
// the bit, 0.4 us for a 0 and 0.8 us for a 1, twenty-four bits an LED, green
// first. Fifty microseconds of quiet at the end is the latch.
//
// The driver in mokxi_ws2812.h makes those pulses with a counted loop rather
// than a timer, because SYSTIMER ticks at 16 MHz, 62.5 ns a tick, and
// reading it takes longer than the pulse being measured. The RMT peripheral
// that would normally do this on a C6 is not modelled (docs/esp32c6.md section
// 7), so bit-banging is not a shortcut here: it is the only way.
//
// There is no floating point in this runtime, so the colour wheel is integers:
// 1536 steps round the six edges of the RGB cube, one channel at full, one at
// nothing and one sliding between them.
#include "mokxi_ws2812.h"
const uint8_t DIN_PIN = 8;
const uint16_t LEDS = 8;
// Three bytes an LED, green first: the order the wire wants them in.
uint8_t pixels[LEDS * 3];
Ws2812 strip(DIN_PIN, pixels, LEDS);
// Where the wheel has got to, and how far apart two neighbours are on it.
uint16_t phase = 0;
const uint16_t SPREAD = 1536 / LEDS;
const uint16_t SPEED = 16;
// Full scale on all eight would be a floodlight. This is a sixth of it.
const uint8_t LEVEL = 40;
const int FRAME_MS = 20;
void setup() {
Serial.begin(115200);
Serial.println("Mokxi ESP32-C6: a rainbow on the RGB LED and seven more");
strip.begin();
strip.clear();
strip.show();
}
void loop() {
for (uint16_t i = 0; i < LEDS; i++) {
uint8_t r;
uint8_t g;
uint8_t b;
ws2812_wheel((uint16_t)(phase + i * SPREAD), &r, &g, &b);
strip.setPixel(i, ws2812_scale(r, LEVEL), ws2812_scale(g, LEVEL),
ws2812_scale(b, LEVEL));
}
strip.show();
phase = (uint16_t)((phase + SPEED) % 1536u);
delay(FRAME_MS);
}
Parts list
3 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
3 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- ESP32-C6-DevKitC-1 pin 8; Addressable RGB LEDs pin DIN
- Ground: ESP32-C6-DevKitC-1 pin GND; Addressable RGB LEDs pin VSS
- ESP32-C6-DevKitC-1 pin 5V; Addressable RGB LEDs pin VDD
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.