Skip to content

Code Description

JinningZ edited this page May 27, 2020 · 7 revisions

Overview

Structure

Set up

Declare and include libraries #include <Arduino.h> #include <AsyncDelay.h> #include "Headers.h" #include "Patterns.h"

Include Sensors: #include <ZX_Sensor.h>

Specify the pin that you are getting input from pinMode(Pin, INPUT); delay(3000);

Tell FastLED about the LED strip configuration FastLED.addLeds<LED_TYPE,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

set master brightness control FastLED.setBrightness(10);

Program Flow Diagram

Flow Diagram

Light Pattern Input && Serial Commands

"BGi 20 20 20 0 169" BGi is the pattern name we are calling.

Then "20 20 20" are the RGB colors we want to use, the range is "0~255".

"0 169" is the start position and the length of the light (patterns). Note that the total length is 169

Parameter Array Parsing

Using a dynamic array, store the instance in the array. In the void loop() function, we loop through the array to see which patterns are enabled and display them.

typedef void (*SimplePatternList[])(); SimplePatternList gPatterns = { BGi, HSv, rainbow, ticks, drumKit, ARGB, fairyFire, funfetti, bell, mouth, addGlitter };

Check to see if each pattern in array is enabled

Call the current pattern if enabled, updating the 'leds' array

for(int i : gPatterns){ if(patternEnArray[i]) gPatternsi; }

Pattern Functions

Create the class of "BGi"

Class bgi. Public: void callPattern();

void bgi::callPattern(): fillsolid(...);

Then declare and create instance;

bgi b1; b1.callPattern();

Content of patterns

fill_solid( &(leds[BGiParams[3]]), BGiParams[4], CRGB( BGiParams[0], BGiParams[1], BGiParams[2]) );

FastLED color library: Click this for more information

Fill rainbow: fill_rainbow( &(leds[BOWParams[1]]), BOWParams[2], gHue, BOWParams[0]);

Other

Sensor Serial Output

Sensor types, what the data looks like

Glitter outputs coordinate of