Adding loop function
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* A single button navigates between shows:
|
||||
* 1 tap — next show
|
||||
* 2 taps — previous show
|
||||
* hold — reset to show 0 (slow blue pulse)
|
||||
* hold — reset to show 0 (blue breath)
|
||||
*
|
||||
* To add or update shows:
|
||||
* 1. Add or edit a .txt file in converter/shows/
|
||||
@@ -66,10 +66,19 @@ static float step_progress(const Step& step) {
|
||||
return (t < 1.0f) ? t : 1.0f;
|
||||
}
|
||||
|
||||
// Complete the current step and advance to the next (loops at end of show).
|
||||
// Complete the current step and advance to the next.
|
||||
// SHOW_LOOP wraps back to step 0; SHOW_SINGLE loads the next show when the last step ends.
|
||||
static void advance_step(CRGB reached_color) {
|
||||
s_from_color = reached_color;
|
||||
s_step_index = (s_step_index + 1) % s_show.length;
|
||||
uint16_t next = s_step_index + 1;
|
||||
if (next >= s_show.length) {
|
||||
if (s_show.mode == SHOW_SINGLE) {
|
||||
load_show((s_show_index + 1) % SHOW_COUNT);
|
||||
return;
|
||||
}
|
||||
next = 0;
|
||||
}
|
||||
s_step_index = next;
|
||||
s_step_start = millis();
|
||||
}
|
||||
|
||||
@@ -78,7 +87,7 @@ static void advance_step(CRGB reached_color) {
|
||||
void setup() {
|
||||
leds_begin();
|
||||
button_begin(BUTTON_PIN);
|
||||
load_show(0); // start on show 0 — slow blue pulse
|
||||
load_show(0); // start on show 0 — blue breath
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -93,7 +102,7 @@ void loop() {
|
||||
load_show((s_show_index + SHOW_COUNT - 1) % SHOW_COUNT);
|
||||
}
|
||||
if (evt == BTN_HOLD) {
|
||||
// Reset to show 0 (blue pulse) from any position.
|
||||
// Reset to show 0 (blue breath) from any position.
|
||||
load_show(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,21 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Show playback modes.
|
||||
#define SHOW_LOOP 0 // repeat the show indefinitely
|
||||
#define SHOW_SINGLE 1 // play once, then auto-advance to the next show
|
||||
|
||||
// One step in a lightshow: a target color and the time to reach it.
|
||||
struct Step {
|
||||
uint8_t r, g, b; // Target RGB color (0–255 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.
|
||||
// Descriptor for one complete show.
|
||||
struct ShowDef {
|
||||
const Step* steps; // Pointer to a PROGMEM Step array
|
||||
uint16_t length; // Number of steps in the array
|
||||
uint8_t mode; // SHOW_LOOP or SHOW_SINGLE
|
||||
};
|
||||
|
||||
// Read one Step from PROGMEM into a regular struct.
|
||||
@@ -41,5 +46,6 @@ 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);
|
||||
sd.mode = pgm_read_byte(&ptr->mode);
|
||||
return sd;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Generated by convert_all.py from: blue_breath.txt
|
||||
// Do not edit manually — edit the .txt file and run: make shows
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#pragma once
|
||||
#include "lightshow_format.h"
|
||||
|
||||
const Step SHOW_BLUE_BREATH[] PROGMEM = {
|
||||
{ 5, 0, 24, 0}, // #050018, 0ms
|
||||
{ 32, 32, 255, 2500}, // #2020FF, 2500ms
|
||||
{ 32, 32, 255, 400}, // #2020FF, 400ms
|
||||
{ 5, 0, 24, 2500}, // #050018, 2500ms
|
||||
{ 5, 0, 24, 800}, // #050018, 800ms
|
||||
};
|
||||
const uint16_t SHOW_BLUE_BREATH_LENGTH = 5;
|
||||
@@ -1,13 +0,0 @@
|
||||
// Generated by convert_all.py from: blue_pulse.txt
|
||||
// Do not edit manually — edit the .txt file and run: make shows
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#pragma once
|
||||
#include "lightshow_format.h"
|
||||
|
||||
const Step SHOW_BLUE_PULSE[] PROGMEM = {
|
||||
{ 5, 0, 37, 0}, // #050025, 0ms
|
||||
{ 40, 40, 255, 3000}, // #2828FF, 3000ms
|
||||
{ 5, 0, 37, 3000}, // #050025, 3000ms
|
||||
};
|
||||
const uint16_t SHOW_BLUE_PULSE_LENGTH = 3;
|
||||
@@ -4,7 +4,7 @@
|
||||
// Do not edit manually — add .txt files to converter/shows/ instead.
|
||||
// =====================================================================
|
||||
//
|
||||
// Show 0 is always the home/reset show (slow blue pulse).
|
||||
// Show 0 is always the home/reset show (blue breath).
|
||||
// Holding the button resets back to show 0.
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
@@ -13,17 +13,17 @@
|
||||
#include "lightshow_format.h"
|
||||
|
||||
// ---- Individual show data ----------------------------------------------
|
||||
#include "show_blue_pulse.h"
|
||||
#include "show_blue_breath.h"
|
||||
#include "show_example_fade.h"
|
||||
#include "show_example_party.h"
|
||||
#include "show_example_pulse.h"
|
||||
|
||||
// ---- Show index (PROGMEM) ----------------------------------------------
|
||||
const ShowDef SHOWS[] PROGMEM = {
|
||||
{SHOW_BLUE_PULSE, SHOW_BLUE_PULSE_LENGTH}, // 0 — home show
|
||||
{SHOW_EXAMPLE_FADE, SHOW_EXAMPLE_FADE_LENGTH}, // 1
|
||||
{SHOW_EXAMPLE_PARTY, SHOW_EXAMPLE_PARTY_LENGTH}, // 2
|
||||
{SHOW_EXAMPLE_PULSE, SHOW_EXAMPLE_PULSE_LENGTH}, // 3
|
||||
{SHOW_BLUE_BREATH, SHOW_BLUE_BREATH_LENGTH, SHOW_LOOP}, // 0 — home show
|
||||
{SHOW_EXAMPLE_FADE, SHOW_EXAMPLE_FADE_LENGTH, SHOW_LOOP}, // 1
|
||||
{SHOW_EXAMPLE_PARTY, SHOW_EXAMPLE_PARTY_LENGTH, SHOW_LOOP}, // 2
|
||||
{SHOW_EXAMPLE_PULSE, SHOW_EXAMPLE_PULSE_LENGTH, SHOW_LOOP}, // 3
|
||||
};
|
||||
|
||||
const uint8_t SHOW_COUNT = 4;
|
||||
|
||||
Reference in New Issue
Block a user