NanoLux (Device) 3.0
Codebase for the open-source AudioLux device.
Loading...
Searching...
No Matches
patterns.cpp File Reference
#include <FastLED.h>
#include <Arduino.h>
#include "patterns.h"
#include "nanolux_types.h"
#include "nanolux_util.h"
#include "storage.h"
#include "audio_analysis.h"
#include "palettes.h"

Macros

#define VOLUME   0
 
#define FREQUENCY   1
 

Functions

void getFhue (uint8_t min_hue, uint8_t max_hue)
 
void getVbrightness ()
 get vol brightness
 
void nextPattern ()
 
void clearLEDSegment (Strip_Buffer *buf, int len)
 
void blank (Strip_Buffer *buf, int len, Pattern_Data *params)
 
void setColorHSV (CRGB *leds, byte h, byte s, byte v, int len)
 
float samplesToStrip (float *samples, int len, float pos)
 
void pix_freq (Strip_Buffer *buf, int len, Pattern_Data *params)
 Based on a sufficient volume, a pixel will float to some position on the light strip and fall down (vol_show adds another threshold)
 
void confetti (Strip_Buffer *buf, int len, Pattern_Data *params)
 Confetti effect using frequency and brightness. Colored speckles that blink and fade smoothly are scattered across the strip.
 
void hue_trail (Strip_Buffer *buf, int len, Pattern_Data *params)
 Outputs a steady moving stream of lights where each pixel correlates to a previous fHue value. Visually tracks pitch over time, with brightness determined by volume. blur configuration adds blur.
 
void saturated (Strip_Buffer *buf, int len, Pattern_Data *params)
 Fills the light strip with a nice ambient mess of colors that shift slowly over time. This function is similar to grovvy noise except the scale and hue_shift values are quiote different. Hue Octave Config remaps the volume to the range of hues present on strip. Hue Shift Config remaps volume as octaves and hhue_shift parameters in fill_noise16() Noise Compression config rremaps volume as hue_x parameter.
 
void groovy (Strip_Buffer *buf, int len, Pattern_Data *params)
 A cool fluctuating pattern that changes color in waves of greens, yellows, purples and blue. This function is similar to saturated_noise but the values of scale and hue_shift are 100 and 5 respectively. This is a moving pattern but it does not change based on and volume or frequency changes. Uses fill_noise16() and blur. Hue Shift Change configuration remaps volume variable as hue_shift.
 
void talking (Strip_Buffer *buf, int len, Pattern_Data *params)
 Generates three clusters of lights, one in the middle, and two symmetric ones that travel out from the center and return. The distance the two outer LEDS from the center is determined by the detected volume. Formant configuration takes the clusters to be red,green,blue. Moving configuration, the three clusters move up and down according to sine wave motion.
 
void glitch (Strip_Buffer *buf, int len, Pattern_Data *params)
 Creates two light clusters that move according to sine wave motion, but their speed is affected by the volume. One pulls its color from fHue, and the other pulls its color from the formant values. Talk configuration combines glitch with talking_moving(). Sections configuration creates 4 seperate sine wave clusters.
 
void bands (Strip_Buffer *buf, int len, Pattern_Data *params)
 Basic band config : Uses the band_split_bounce() function to generate a five band split, and maps that split to the light strip. The strip is broken into five chunks of different colors, where the volume of each band determines how much of each section of the LED strip is lit. Advanced bands config : he strip is broken into five chunks of different colors, where the volume of each band determines how much of each section is lit, and that portion will diminish over time if a certain volume threshold is not met Fomant bands config: emonstrates the formant feature of the audio analysis code. Each of the three formant values correspond to a third of the entire LED strip, where the individual formant values determine the hue of each third.
 
void eq (Strip_Buffer *buf, int len, Pattern_Data *params)
 Short and sweet function. Each pixel corresponds to a value from vReal, where the volume at each pitch determines the brightness of each pixel. Hue is locked in to a rainbow.
 
void random_raindrop (Strip_Buffer *buf, int len, Pattern_Data *params)
 A random spot is chosen along the length and does a ripple based on frequency.
 
void Fire2012 (Strip_Buffer *buf, int len, Pattern_Data *params)
 Fire2012 pattern utilizing heating and cooling.
 
void bar_fill (Strip_Buffer *buf, int len, Pattern_Data *params)
 Displays a pattern that occupies "lower" pixels at lower values, and "higher" pixels at higher values.
 
int getColor (int noteNumber)
 
void blendIn (Strip_Buffer *buf, int len, Pattern_Data *params)
 Maps the LED strip to the different frequencies, and each LED blends between two different colors based on that frequency's amplitude.
 
void bleedThrough (Strip_Buffer *buf, int len, Pattern_Data *params)
 A color blended between a base and transitioning color is sent down the LED strip. The blending is based off of the cumulative volume of the audio. When the color is fully blended into the transitioning color, that color becomes the new base color and a new transitioning color is selected.
 
CHSV getColorForNote (int noteNumber)
 
void synesthesiaRolling (Strip_Buffer *buf, int len, Pattern_Data *params)
 Maps the current note to a color.
 
void noteEQ (Strip_Buffer *buf, int len, Pattern_Data *params)
 Maps the current note to a section on the led strip.
 
CHSV getStringColor (int noteNumber, double volum)
 
double findString (double frequency)
 
void stringTheory (Strip_Buffer *buf, int len, Pattern_Data *params)
 Maps the LED strip to a string on a violin. The color changes based on which string of the violin is detected, and position is based on where on the string is pressed to create the detected frequency.
 
void splashTheory (Strip_Buffer *buf, int len, Pattern_Data *params)
 Maps the LED strip to volume. The starting position is based on the volume of the sampled audio. It then creates a random variance from that starting point, and creates a splashing effect at that final point. The hue is determined by the frequency of the audio. If two splashing effects overlap, the one with a higher brightness value (aka newer/closer splash) will proliferate as normal.
 
void deltaHeat (Strip_Buffer *buf, int len, Pattern_Data *params)
 Maps the LED strip to frequencies. Creates a heatmap, where frequencies that have had drastic/continued changes to their amplitude are reflected as "hot" in the heatmap, while areas with lower activity are "cooler" or "cooling down".
 

Variables

unsigned long microseconds
 
AudioAnalysis audioAnalysis
 External reference to the AudioAnalysis instance.
 
bool button_pressed
 Contains the current state of the button (true is pressed).
 
SimplePatternList gPatterns
 
int NUM_PATTERNS
 
SimplePatternList gPatterns_layer
 
double a
 
uint8_t fHue
 Contains the "base" hue, calculated from the peak frequency.
 
uint8_t vbrightness
 Contains the "base" brightness value, calculated from the current volume.
 
int advanced_size
 
CRGBPalette16 gPal = GMT_hot_gp
 
bool gReverseDirection = false
 
Config_Data config
 The currently-loaded device config.
 
Pattern_Data params
 
uint8_t manual_pattern_idx
 
bool manual_control_enabled
 MANUAL CONTROL VARIABLES.
 

Detailed Description

This file contains all defined pattern handlers.

The pattern refactor is still in-progress, so this file currently has little in-line documentation.

Function Documentation

◆ bands()

void bands ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Basic band config : Uses the band_split_bounce() function to generate a five band split, and maps that split to the light strip. The strip is broken into five chunks of different colors, where the volume of each band determines how much of each section of the LED strip is lit. Advanced bands config : he strip is broken into five chunks of different colors, where the volume of each band determines how much of each section is lit, and that portion will diminish over time if a certain volume threshold is not met Fomant bands config: emonstrates the formant feature of the audio analysis code. Each of the three formant values correspond to a third of the entire LED strip, where the individual formant values determine the hue of each third.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ bar_fill()

void bar_fill ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Displays a pattern that occupies "lower" pixels at lower values, and "higher" pixels at higher values.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ bleedThrough()

void bleedThrough ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

A color blended between a base and transitioning color is sent down the LED strip. The blending is based off of the cumulative volume of the audio. When the color is fully blended into the transitioning color, that color becomes the new base color and a new transitioning color is selected.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ blendIn()

void blendIn ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Maps the LED strip to the different frequencies, and each LED blends between two different colors based on that frequency's amplitude.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ confetti()

void confetti ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Confetti effect using frequency and brightness. Colored speckles that blink and fade smoothly are scattered across the strip.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ deltaHeat()

void deltaHeat ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Maps the LED strip to frequencies. Creates a heatmap, where frequencies that have had drastic/continued changes to their amplitude are reflected as "hot" in the heatmap, while areas with lower activity are "cooler" or "cooling down".

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ eq()

void eq ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Short and sweet function. Each pixel corresponds to a value from vReal, where the volume at each pitch determines the brightness of each pixel. Hue is locked in to a rainbow.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ Fire2012()

void Fire2012 ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Fire2012 pattern utilizing heating and cooling.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ glitch()

void glitch ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Creates two light clusters that move according to sine wave motion, but their speed is affected by the volume. One pulls its color from fHue, and the other pulls its color from the formant values. Talk configuration combines glitch with talking_moving(). Sections configuration creates 4 seperate sine wave clusters.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ groovy()

void groovy ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

A cool fluctuating pattern that changes color in waves of greens, yellows, purples and blue. This function is similar to saturated_noise but the values of scale and hue_shift are 100 and 5 respectively. This is a moving pattern but it does not change based on and volume or frequency changes. Uses fill_noise16() and blur. Hue Shift Change configuration remaps volume variable as hue_shift.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ hue_trail()

void hue_trail ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Outputs a steady moving stream of lights where each pixel correlates to a previous fHue value. Visually tracks pitch over time, with brightness determined by volume. blur configuration adds blur.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ noteEQ()

void noteEQ ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Maps the current note to a section on the led strip.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ pix_freq()

void pix_freq ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Based on a sufficient volume, a pixel will float to some position on the light strip and fall down (vol_show adds another threshold)

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ random_raindrop()

void random_raindrop ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

A random spot is chosen along the length and does a ripple based on frequency.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ saturated()

void saturated ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Fills the light strip with a nice ambient mess of colors that shift slowly over time. This function is similar to grovvy noise except the scale and hue_shift values are quiote different. Hue Octave Config remaps the volume to the range of hues present on strip. Hue Shift Config remaps volume as octaves and hhue_shift parameters in fill_noise16() Noise Compression config rremaps volume as hue_x parameter.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ splashTheory()

void splashTheory ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Maps the LED strip to volume. The starting position is based on the volume of the sampled audio. It then creates a random variance from that starting point, and creates a splashing effect at that final point. The hue is determined by the frequency of the audio. If two splashing effects overlap, the one with a higher brightness value (aka newer/closer splash) will proliferate as normal.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ stringTheory()

void stringTheory ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Maps the LED strip to a string on a violin. The color changes based on which string of the violin is detected, and position is based on where on the string is pressed to create the detected frequency.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ synesthesiaRolling()

void synesthesiaRolling ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Maps the current note to a color.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

◆ talking()

void talking ( Strip_Buffer * buf,
int len,
Pattern_Data * params )

Generates three clusters of lights, one in the middle, and two symmetric ones that travel out from the center and return. The distance the two outer LEDS from the center is determined by the detected volume. Formant configuration takes the clusters to be red,green,blue. Moving configuration, the three clusters move up and down according to sine wave motion.

Parameters
bufPointer to the Strip_Buffer structure, holds LED buffer and history variables.
lenThe length of LEDs to process
paramsPointer to Pattern_Data structure containing configuration options.

Variable Documentation

◆ button_pressed

bool button_pressed
extern

Contains the current state of the button (true is pressed).

Checks if the device button is pressed, defined in main.ino.

◆ config

Config_Data config
extern

The currently-loaded device config.

The current config of the device, defined in main.ino. Used to check if serial printing is allowed.