Matrix refresh effect, and Random really picks from all effects

Yellow streaks fall down the columns that changed, at random moments, and
leave the new image behind them. The start ticks come from a hash, so the
only new RAM is one bit per column. Only a dot's final flip gets all pulses.

Random took micros() % 8, but micros() only gives multiples of 4 on the
Nano, so it could only pick sparkle or diagonal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-04 02:28:34 +01:00
1 parent 35e678d78d
commit 8fcb17c395
13 files changed
+345 -19

No files matched your search

+70 -2
View File
@@ -15,6 +15,9 @@ BROSE9323::BROSE9323(uint8_t w, uint8_t h, uint8_t pw, uint16_t ft) : Adafruit_G
_old_buffer = (uint8_t *)calloc(_buffer_size, sizeof(uint8_t));
#endif
_new_buffer = (uint8_t *)calloc(_buffer_size, sizeof(uint8_t));
#ifndef ESPSERIAL
_changed_columns = (uint8_t *)calloc(_buffer_width, sizeof(uint8_t));
#endif
}
#ifdef ESPSERIAL
@@ -424,9 +427,14 @@ void BROSE9323::_startEffect(bool all, bool instant)
{
uint16_t total = width() * height();
uint16_t changed = 0;
memset(_changed_columns, 0, _buffer_width);
for (uint8_t y = 0; y < height(); y++)
for (uint8_t x = 0; x < width(); x++)
changed += _changed(x, y);
if (_changed(x, y))
{
changed++;
_changed_columns[x >> 3] |= 1 << (x & 7);
}
if (changed == 0 && !all)
{
_animating = false;
@@ -438,7 +446,7 @@ void BROSE9323::_startEffect(bool all, bool instant)
if (effect != EFFECT_INSTANT && (_effect_flags & EFFECT_FLAG_SMALL_ONLY) && (all || changed > total / 10))
effect = EFFECT_INSTANT;
if (effect == EFFECT_RANDOM)
effect = 1 + micros() % (EFFECT_RANDOM - 1);
effect = randomEffect(micros());
// Pushing needs to know what is shown; after boot that is unknown
if (all && effect == EFFECT_PUSH)
effect = EFFECT_WIPE;
@@ -462,6 +470,15 @@ void BROSE9323::_startEffect(bool all, bool instant)
_push_pos = 0;
steps = width();
}
else if (effect == EFFECT_MATRIX)
{
_push_shift = 0;
_push_pos = 0;
_matrix_seed = micros() >> 2;
if (all)
memset(_changed_columns, 0xFF, _buffer_width);
steps = matrixTicks(height());
}
else
{
_sequence.begin(effect == EFFECT_FLAP ? EFFECT_WIPE : effect, width(), height(), (uint16_t)micros());
@@ -517,6 +534,48 @@ bool BROSE9323::_pushDot(void)
return ++_push_shift <= w;
}
// The next flip of the current matrix tick. _push_pos walks over two places per column: the
// streak's head (turns the dot yellow), then its tail (the new image). Only the changed
// columns have a streak. Only a dot's final flip gets all pulses, so the head gives a dot
// that ends up black just one: a full screen change takes much less time. False when all
// ticks are done.
bool BROSE9323::_matrixStep(void)
{
uint8_t w = width(), h = height();
uint8_t spread = matrixStartSpread(h);
while (true)
{
uint8_t x = _push_pos >> 1;
bool tail = _push_pos & 1;
bool flipped = false;
if (_changed_columns[x >> 3] & (1 << (x & 7)))
{
int16_t row = (int16_t)_push_shift - matrixStartTick(x, _matrix_seed, spread);
if (tail)
row -= MATRIX_STREAK;
if (row >= 0 && row < h)
{
bool wanted = _wanted(x, row);
bool target = tail ? wanted : true;
bool changed = _shown(x, row) != target;
if (changed || _animate_all)
{
_flipTo(x, row, target, changed && (tail || wanted) ? _pulses : 1);
flipped = true;
}
}
}
if (++_push_pos >= (uint16_t)w * 2)
{
_push_pos = 0;
_next_step += _step_time;
return ++_push_shift < matrixTicks(h);
}
if (flipped)
return true;
}
}
bool BROSE9323::busy(void) const
{
return _animating && !_drawing;
@@ -548,6 +607,15 @@ bool BROSE9323::update(void)
}
continue;
}
if (_running_effect == EFFECT_MATRIX)
{
if (!_matrixStep())
{
_animating = false;
break;
}
continue;
}
uint8_t x, y;
if (!_sequence.next(x, y))