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 "core_analysis.h"
#include "ext_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)
 
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 tug_of_war (Strip_Buffer *buf, int len, Pattern_Data *params)
 Strip is split into two sides, red and blue showing push and pull motion based on either frequency or volume.
 
void Fire2012 (Strip_Buffer *buf, int len, Pattern_Data *params)
 Fire2012 pattern utilizing heating and cooling.
 
void vowels_raindrop (Strip_Buffer *buf, int len, Pattern_Data *params)
 
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.
 

Variables

unsigned long microseconds
 
double vReal [SAMPLES]
 
double vImag [SAMPLES]
 Imaginary component of vReal. Unused.
 
double vRealHist [SAMPLES]
 Last state of the vReal array.
 
double delt [SAMPLES]
 
bool button_pressed
 Contains the current state of the button (true is pressed).
 
SimplePatternList gPatterns
 
int NUM_PATTERNS
 
SimplePatternList gPatterns_layer
 
double peak
 Contains the peak frequency detected by the FFT.
 
uint8_t fHue
 Contains the "base" hue, calculated from the peak frequency.
 
double volume
 Contains the current volume detected by the FFT.
 
uint8_t vbrightness
 Contains the "base" brightness value, calculated from the current volume.
 
double maxDelt
 
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.
 
double fbs [5]
 
double formants [3]
 Global formant array, used for accessing.
 

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ tug_of_war()

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

Strip is split into two sides, red and blue showing push and pull motion based on either frequency or volume.

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.

◆ delt

double delt[SAMPLES]
extern

Variable used to store the frequency delta between vReal and vRealHist.

◆ fbs

double fbs[5]
extern

Global FIVE BAND SPLIT which stores changing bands based on raw frequencies

◆ maxDelt

double maxDelt
extern

Global variable used to access the frequency band with the largest delta between iterations.

◆ peak

double peak
extern

Contains the peak frequency detected by the FFT.

Global variable used to store preak audio frequency.

◆ volume

double volume
extern

Contains the current volume detected by the FFT.

Global variable used to access the current volume.

◆ vReal

double vReal[SAMPLES]
extern

Array to store both sampled and FFT'ed audio. Processing is done in place.