Skip to content

Commit

Permalink
Finished Dynamic Chaser Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
LivingSynthesis committed Nov 18, 2023
1 parent a250fdf commit a3e0281
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions VortexEngine/src/Patterns/Multi/Sequencer/ChaserPattern.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "ChaserPattern.h"

// This controlls the ratio of chaser dots to LED_COUNT. Default 1 chaser per 7 LEDs.
#define CHASER_RATIO 7

// This pattern aims to be a demonstration of the sequencer.
// There are always many ways to implement a pattern, it's best
// to choose the method that is most suitable for the pattern.
Expand All @@ -9,39 +12,31 @@ ChaserPattern::ChaserPattern(const PatternArgs &args) :
setArgs(args);
// set the pattern ID
//m_patternID = PATTERN_CHASER;
// There are 8 steps in the chaser, so iterate 8 times and generate
// There are LED_COUNT steps in the chaser, so iterate LED_COUNT times and generate
// a pattern map for each step. A colorset map can also be applied
// to override certain colors for specific steps, but that's not
// what is being done here
for (uint8_t i = 0; i < LED_COUNT; ++i) {
// Each step all fingers are dops except for one, so start with a
// Pattern Map that has dops on all fingers. A Pattern Map will map
// Each step all LEDs are dops except for one, so start with a
// Pattern Map that has dops on all LEDs. A Pattern Map will map
// a Pattern ID to each LED on the device, then we will override a
// different entry each step with the Pattern ID for Solid0.
PatternMap patMap(PATTERN_DOPS);
// Override a single finger in the pattern map with the Solid0 pattern
// Override a single LED in the pattern map with the Solid0 pattern
// which will use the 0th color from the colorset as the solid color.
// An LedMap is a bitmap that indicates which leds are turned on or off
// at any given time. This will generate an Led Map based on the current
// step index like this:
//
// step -> finger index -> target leds -> LedMap
// -----------------------------------------------------
// 0 0 0, 1 00 00 00 00 11
// 1 1 2, 3 00 00 00 11 00
// 2 2 4, 5 00 00 11 00 00
// 3 3 6, 7 00 11 00 00 00
// 4 4 8, 9 11 00 00 00 00
// 5 3 6, 7 00 11 00 00 00
// 6 2 4, 5 00 00 11 00 00
// 7 1 2, 3 00 00 00 11 00
LedMap overrideLeds = MAP_LED(i) | MAP_LED((i + LED_COUNT/4) % LED_COUNT) | MAP_LED((i + LED_COUNT / 2) % LED_COUNT) | MAP_LED((i + (3* LED_COUNT / 4)) % LED_COUNT); //MAP_PAIR((Pair)((i < 5) ? i : (8 - i)));
LedMap overrideLeds = 0;
// This creates an led map with 1 chaser per CHASER_RATIO (default 7) leds in LED_COUNT
for (int chaserCount = 0; chaserCount < (LED_COUNT / CHASER_RATIO); ++chaserCount) {
overrideLeds |= MAP_LED((i + (chaserCount * CHASER_RATIO)) % LED_COUNT);
}
// Then this API is used to override specific positions in the Pattern Map
// with a different pattern ID, we use the Led Map generated above to tell
// setPatternAt() which indices to override with Solid0
patMap.setPatternAt(PATTERN_SOLID, overrideLeds);
// Then finally we add this pattern mapping to the sequence in a new step
// that will last 300ms, this means all 8 steps will be 300ms each.
// that will last 300ms, this means all LED_COUNT steps will be 300ms each.
// The last parameter of addStep() is omitted, that parameter could be used
// to override the colorset for specific Leds on any given step. Since it
// is omitted that means this pattern will use whichever colorset is chosen
Expand Down

0 comments on commit a3e0281

Please sign in to comment.