Files
Amirine_Cosplay_Lights/arduino/cosplay_lights/lightshow_format.h
T
bgrolleman 11eb2584ef Initial commit — Amirine Cosplay Lights
Arduino Uno + WS2812B LED strip controller with a text-based lightshow
system. Shows are defined as .txt files (hex color + fade duration per step),
converted to PROGMEM headers by convert_all.py, and navigated at runtime
via a debounced button (tap/double-tap/hold). BSD 2-Clause license.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 10:16:56 +02:00

46 lines
1.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* lightshow_format.h — Core data structures for show playback.
*
* All show data lives in PROGMEM (flash memory) to preserve the
* Arduino Uno's 2KB of RAM. The read_* helpers copy values out of
* PROGMEM so the rest of the code can work with them normally.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <avr/pgmspace.h>
#include <stdint.h>
// One step in a lightshow: a target color and the time to reach it.
struct Step {
uint8_t r, g, b; // Target RGB color (0255 each)
uint16_t duration_ms; // Milliseconds to fade from the previous color (0 = instant)
};
// Descriptor for one complete show: a pointer to its PROGMEM Step array and its length.
struct ShowDef {
const Step* steps; // Pointer to a PROGMEM Step array
uint16_t length; // Number of steps in the array
};
// Read one Step from PROGMEM into a regular struct.
// Direct pointer access does not work for PROGMEM on AVR — use this helper.
inline Step read_step(const Step* ptr) {
Step s;
s.r = pgm_read_byte(&ptr->r);
s.g = pgm_read_byte(&ptr->g);
s.b = pgm_read_byte(&ptr->b);
s.duration_ms = pgm_read_word(&ptr->duration_ms);
return s;
}
// Read one ShowDef from a PROGMEM ShowDef array.
// On AVR, pointers are 2 bytes wide, so pgm_read_word works for both fields.
inline ShowDef read_show_def(const ShowDef* ptr) {
ShowDef sd;
sd.steps = (const Step*)pgm_read_word(&ptr->steps);
sd.length = pgm_read_word(&ptr->length);
return sd;
}