Skip to content

Commit

Permalink
0.2 beta (#17)
Browse files Browse the repository at this point in the history
* fix: code organization and simplification

* feat: layer effects

* wip: linked activations

* wip: remove superfluous helper methods from pattern

* wip: linked activations and deactivations

* wip: bind color to periods with one method call

* docs

* update readme

* gitignore

* ignore dirs

* readme updates

* Delete .gitignore

* Delete misc.xml

* Delete modules.xml

* Delete quickPatterns.iml

* Delete vcs.xml

* Delete settings.json
  • Loading branch information
brimshot authored Dec 19, 2021
1 parent d6809c8 commit 24d0df0
Show file tree
Hide file tree
Showing 47 changed files with 1,557 additions and 978 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
/.vscode
236 changes: 172 additions & 64 deletions README.md

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions examples/bulb_lights/bulb_lights.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ SOFTWARE.
#include <quickPatterns.h>

#define CHIPSET WS2811
#define DATA_PIN 8
#define DATA_PIN 2
#define NUM_LEDS 100
#define BRIGHTNESS 32
#define BRIGHTNESS 64
#define COLOR_ORDER RGB //GRB for WS2812, RGB for WS2811
#define TICKLENGTH 25

Expand All @@ -47,6 +47,7 @@ void setup() {
delay(3000); // Recovery delay

randomSeed(analogRead(1));
// random16_add_entropy(analogRead(0));

// ~ Configure FastLED

Expand All @@ -64,7 +65,7 @@ void setup() {
quickPatterns.setTickMillis(TICKLENGTH);

// ~

quickPatterns.addPattern(new qpPaletteDissolve(5))
.usePalette(ForestColors_p);

Expand All @@ -74,17 +75,16 @@ void setup() {
.stayActiveForNTicks(80, 140);
quickPatterns.sameLayer().setLayerBrush(COMBINE).continuallyFadeLayerBy(30);


// ~

quickPatterns.newScene().addPattern(new qpPaletteWave(5))
.usePalette(CRGBPalette16(CRGB::Yellow, CRGB::Orange, CRGB::Goldenrod, CRGB::Red));

quickPatterns.sameScene().addPattern(new qpSparkles(6))
.chooseColorFromPalette(CRGBPalette16(CRGB::Red, CRGB(120, 0, 255)), SEQUENTIAL);
.chooseColorFromPalette(CRGBPalette16(CRGB::Red, CRGB(120, 0, 255)), SEQUENTIAL)
.changeColorEveryNTicks(2);
quickPatterns.sameLayer().continuallyFadeLayerBy(20);


// ~

quickPatterns.newScene().addPattern(new qpPaletteWave(5))
Expand Down Expand Up @@ -118,9 +118,7 @@ void setup() {
void loop()
{

// Refresh lights only when new frame data available, prevents issues with data timing on fast processors
if(quickPatterns.draw())
FastLED.show();
quickPatterns.show();

EVERY_N_SECONDS(30) {
quickPatterns.nextScene();
Expand Down
266 changes: 266 additions & 0 deletions examples/quickPatternsDemoReel/quickPatternsDemoReel.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
/*****************************************************
quickPatterns demo reel - patterns to demonstrate some of the options available in the quickPatterns library
https://github.com/brimshot/quickPatterns
MIT License
Copyright (c) 2021 Chris Brim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*****************************************************/

#ifdef CORE_TEENSY
#define FASTLED_ALLOW_INTERRUPTS 0
#endif

#include <quickPatterns.h>

//////////////////////////////////
// HARDWARE CONSTANTS
//////////////////////////////////

#define CHIPSET WS2812B
#define DATA_PIN 2
#define NUM_LEDS 150
#define BRIGHTNESS 64
#define COLOR_ORDER GRB //GRB for WS2812, RGB for WS2811


//////////////////////////////////
// CUSTOM PATTERNS FOR THIS SKETCH
//
// For information on writing custom patterns for use with quickPatterns see: https://github.com/brimshot/quickPatterns
//
//////////////////////////////////

// A juggle effect that slowly increases speed over time
class increasingJuggle : public qpPattern {

private:
const int MAX_SPEED = 2;
const int FRAMES_TO_SHOW_AT_MAX_SPEED = 200;

int _startingSpeed;
int speed;
int velocity = 0;
int framesRenderedAtMaxSpeed = 0;

void reset()
{
speed = _startingSpeed;
velocity = framesRenderedAtMaxSpeed = 0;
}

public:

increasingJuggle(int startingSpeed)
{
_startingSpeed = speed = startingSpeed;
}

void draw() {

// Speed limiter
if(this->frames % speed)
return;

// Do juggle
for( int i = 0; i < 8; i++)
_targetLeds[beatsin16(i+7, 0, _numLeds - 1)] = _getColor();

// Increase velocity on each render
velocity += 1;
if(velocity%10 == 0)
speed = max(--speed, MAX_SPEED);

// Stay at max speed for 200 frames then start over
if(speed == MAX_SPEED) {
if(++framesRenderedAtMaxSpeed == 200) {
reset();
}
}

}

};


// Sends segments of lights down the strip one by one and stacks them at the end
class segmentStacker : public qpPattern {

private:
const int FRAMES_TO_SHOW_WITH_FULL_STACK = 200;

int stackSize = 0;
int segmentSize = 0;
int segmentPos = 0;
int framesWithFullStack = 0;

void reset() { segmentPos = stackSize = framesWithFullStack = 0; }

public:

segmentStacker(int segmentSize) : segmentSize(segmentSize) {}

void draw() {

// -. Quick note: we do NOT clear the leds here at the beginning of each loop since we are expecting other patterns on the same layer to do it for us

// Draw stack
for(int i = (_numLeds-1); i > ((_numLeds-1) - stackSize); i--) {
_targetLeds[i] = _getColor();
}

// Pause or reset at end
if(stackSize >= (_numLeds-1)) {
if(framesWithFullStack < FRAMES_TO_SHOW_WITH_FULL_STACK) {
framesWithFullStack++;
return;
}

reset();
_countCycle();
return;
}

// Draw segment
for(int i = segmentPos; i < (segmentPos + segmentSize); i++) {
_targetLeds[i] = _getColor();
}

// Advance segment pos for next frame
segmentPos++;

// If we bumped into our stack, add it
if((segmentPos + segmentSize) >= ((_numLeds-1) - stackSize)) {
stackSize += segmentSize;
segmentPos = 0;
}

}

};


//////////////////////////////////
// MAIN SKETCH BEGINS HERE
//////////////////////////////////

// Declare array of CRGB objects for use with FastLED
CRGB leds[NUM_LEDS];

// declare quickPatterns controller and pass in main led array
quickPatterns quickPatterns(leds, NUM_LEDS);

void setup() {

delay(3000); // Recovery delay

random16_add_entropy(analogRead(0));

// ~ Configure FastLED

FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection(TypicalLEDStrip)
.setDither(BRIGHTNESS < 255);

FastLED.setBrightness(BRIGHTNESS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 450);

FastLED.clear();


/////////// quickPatterns setup

// ----- Scene 1: Rainbow base layers with sparkling highlights that increase in speed as they shine

quickPatterns.newScene().addPattern(new qpPaletteGradient(2))
.usePalette(RainbowColors_p)
.drawEveryNTicks(2);

// Decoration layer: juggles that increase in speed then reset after a short time
quickPatterns.sameScene().addPattern(new increasingJuggle(12))
.singleColor(CRGB(128, 128, 128));
quickPatterns.sameLayer().setLayerBrush(ADD).continuallyFadeLayerBy(20);

// ----- End Scene 1

// ----- Scene 2: Twinkling rainbow that is slowly revealed by stacking a visible window segment by segment

quickPatterns.newScene().addPattern(new qpPaletteTwinkle(12))
.usePalette(RainbowColors_p);

quickPatterns.sameScene().addPattern(new qpFill())
.singleColor(CRGB::Black);

quickPatterns.sameLayer().addPattern(new segmentStacker(10))
.singleColor(CRGB::White);
quickPatterns.sameLayer().setLayerBrush(MASK);

// ----- End Scene 2


// ----- Scene 3: three overlapping layers at different speeds

quickPatterns.newScene().addPattern(new qpBouncingBars(9)) // blue bars, 9 pixels width
.singleColor(CRGB::Blue);

quickPatterns.sameScene().addPattern(new qpBouncingBars(5)) // short red bars, 5 pixels
.singleColor(CRGB::Red);
quickPatterns.sameLayer().setLayerBrush(ADD); //when passing over underlying pixels, add their light together

quickPatterns.sameScene().addPattern(new qpBouncingBars(5)) // slow yellow bars, 5 pixels
.singleColor(CRGB::Yellow)
.drawEveryNTicks(3); //move at a slower speed
quickPatterns.sameLayer().setLayerBrush(COMBINE);

// ----- End Scene 3


// ----- Scene 4: Linked activations and deactivations

qpPattern &Sinelon = quickPatterns.newScene().addPattern(new qpSinelon(16))
.chooseColorFromPalette(RainbowColors_p, SEQUENTIAL)
.changeColorEveryNTicks(2);
quickPatterns.sameLayer().continuallyFadeLayerBy(20);

qpPattern &WhiteLightning = quickPatterns.sameScene().addPattern(new qpLightning(12))
.singleColor(CRGB::White)
.activateWhenPatternPHasCompletedNCycles(Sinelon, 2)
.stayActiveForNCycles(2);

quickPatterns.sameScene().addPattern(new qpLightning(20))
.singleColor(CRGB(200, 0, 180))
.activateWhenPatternPHasDeactivatedNTimes(WhiteLightning, 3) //After pattern p has activated 3 times... possible?
.stayActiveForNCycles(4);

// ----- End Scene 4


}

void loop()
{
quickPatterns.show();

EVERY_N_MINUTES(1) {
quickPatterns.nextScene();
}
}
10 changes: 10 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=quickPatterns
version=0.2
author=Chris Brim <[email protected]>
maintainer=Chris Brim <[email protected]>
sentence=A FastLED based patterns manager for addressable LEDs (WS2812B, NeoPixels, etc.) that allows multiple animations to run simultaneously on the same strand of lights with configurable colors and timings.
paragraph=The goal of quickPatterns is to provide makers a simple interface in code for building advanced light pattern configurations i.e. multiple patterns running simultaneously with timed and sequenced pattern activation.
category=Display
url=https://github.com/brimshot/quickPatterns
includes=quickPatterns.h
depends=FastLED
Loading

0 comments on commit 24d0df0

Please sign in to comment.