Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FastLED Setup
- #define FASTLED_INTERNAL
- #include "FastLED.h"
- #define LEDstrips 28
- #define LEDper 60
- #define LEDtype WS2813
- #define LEDcorr TypicalSMD5050
- #define LEDdither 255 //try 0 to reduce flickering
- uint8_t LEDbright = 100;
- int LEDamps = 1000;
- CRGB leds[LEDstrips][LEDper];
- uint8_t hue = 155;
- int rowcount;
- int colcount;
- int count;
- byte glitterchance = 0;
- // MSGEQ7
- #include "MSGEQ7.h"
- #define EQ7pin A7
- #define EQ7reset PIN_C7
- #define EQ7strobe PIN_C5
- #define EQ7interval ReadsPerSecond(50)
- #define EQ7smooth 200
- #define nz 20
- CMSGEQ7<EQ7smooth, EQ7reset, EQ7strobe, EQ7pin> MSGEQ7;
- float EQ7avg[7];
- float EQ7peak[7];
- DEFINE_GRADIENT_PALETTE( purplecascade ){
- 0, 0, 0, 0, //black
- 120, 155, 0, 255, //purple
- 235, 255, 0, 40, //crimson
- 255, 255,255,255 }; //full white
- DEFINE_GRADIENT_PALETTE( cyber ){
- 0, 0, 0, 0,
- 120, 240,0,0,
- 235, 255, 200, 0,
- 255, 255,255,255
- };
- DEFINE_GRADIENT_PALETTE( blackwhite ){
- 0, 0, 0, 0,
- 127, 0, 0, 0,
- 128, 255, 255, 255,
- 255, 255, 255, 255};
- void setup() {
- // put your setup code here, to run once:
- // Initialize LEDs
- FastLED.setMaxPowerInVoltsAndMilliamps(5,LEDamps); //play with the order here
- //FastLED.setTemperature();
- FastLED.setBrightness(LEDbright);
- FastLED.setDither(LEDdither);
- FastLED.addLeds<LEDtype, PIN_C4, GRB>(leds[0], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C3, GRB>(leds[1], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C2, GRB>(leds[2], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C1, GRB>(leds[3], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C0, GRB>(leds[4], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_E1, GRB>(leds[5], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_E0, GRB>(leds[6], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_D7, GRB>(leds[7], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_D6, GRB>(leds[8], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_D5, GRB>(leds[9], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_D4, GRB>(leds[10], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_D1, GRB>(leds[11], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_D0, GRB>(leds[12], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_B7, GRB>(leds[13], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_B4, GRB>(leds[14], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_B3, GRB>(leds[15], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_B2, GRB>(leds[16], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_B1, GRB>(leds[17], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_B0, GRB>(leds[18], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_E7, GRB>(leds[19], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_E6, GRB>(leds[20], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F0, GRB>(leds[21], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F1, GRB>(leds[22], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F2, GRB>(leds[23], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F3, GRB>(leds[24], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F4, GRB>(leds[25], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F5, GRB>(leds[26], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F6, GRB>(leds[27], LEDper).setCorrection(LEDcorr);
- FastLED.clear();
- FastLED.show();
- // Initialize other components
- Serial.begin(9600);
- Serial.println("start");
- }
- void loop() { //add state 1 mili?
- dualwave();
- //doublehelix();
- hue = hue + 1;
- FastLED.show();
- }
- /*oid spiral(){
- FastLED.clear();
- byte hueadd = 0;
- byte top = 0;
- byte right = LEDstrips -1;
- byte bottom = LEDper - 1;
- byte left = 0;
- while(top < (LEDper/2 - 1) && right > (LEDstrips/2 - 1) && bottom > (LEDstrips/2 - 1) && left < (LEDstrips/2 - 1)){
- for(int col = left; col < right; col++){
- leds[col][top] = CHSV(hue+hueadd, 255, 255);
- hueadd++;
- FastLED.show();
- }
- top++;
- for(int row = top; row < bottom; row++){
- leds[right][row] = CHSV(hue+hueadd, 255, 255);
- hueadd++;
- FastLED.show();
- }
- right--;
- for(int col = right; col > left; col++){
- leds[col][bottom] = CHSV(hue+hueadd, 255, 255);
- hueadd++;
- FastLED.show();
- }
- bottom--;
- for(int row = bottom; row > top; row++){
- leds[left][row] = CHSV(hue+hueadd, 255, 255);
- hueadd++;
- FastLED.show();
- }
- left++;
- }
- }
- */
- void dualwave(){
- FastLED.clear();
- CRGBPalette16 palette = cyber;
- for(int x = 0; x < LEDper; x++){
- uint8_t stungus = (hue + count + x*beatsin8(1, 1, 8)); // Fill sine status
- stungus = sin8(stungus);
- uint8_t gungus = stungus + 128;
- stungus = map(stungus, 0, 255, 2, 25);
- gungus = map(gungus, 0, 255, 2, 25);
- leds[stungus][x] = CHSV(255, 0, 0);
- leds[gungus][x] = CHSV(255, 0, 0);
- for(byte left = 0; left < stungus; left++){
- leds[left][x] = ColorFromPalette(palette, rowcount + x*5, 255, LINEARBLEND);
- }
- CRGBPalette16 palette = purplecascade;
- for(byte right = LEDstrips-1; right > gungus; right--){
- leds[right][x] = ColorFromPalette(palette, hue + x*5, 255, LINEARBLEND);
- }
- }
- count++;
- rowcount = rowcount - beatsin8(20, 1, 7);
- hue = hue + beatsin8(10, 1, 6);
- }
- void doublehelix(){
- FastLED.clear();
- for(int x = 0; x < LEDper; x++){
- uint8_t stungus = (hue + count + x*2); // beatsin8(1, 1, 8)
- stungus = sin8(stungus); // Calculate sine position
- uint8_t gungus = stungus + 128; // Copy 180 degrees out of phase
- stungus = map(stungus, 0, 255, 2, 25); // Map to LEDs
- gungus = map(gungus, 0, 255, 2, 25);
- for(byte col = 0; col < LEDper; col++){
- if(col < stungus && col < gungus){
- CRGBPalette16 palleft = cyber;
- leds[col][x] = ColorFromPalette(palleft, rowcount + x*5, 255, LINEARBLEND);
- Serial.println("gug");
- }
- if(col > stungus && col > gungus){
- CRGBPalette16 palright = purplecascade;
- leds[col][x] = ColorFromPalette(palright, hue + x*5, 255, LINEARBLEND);
- }
- if(col > stungus && col < gungus){
- CRGBPalette16 palmid = blackwhite;
- leds[col][x] = ColorFromPalette(palmid, rowcount + x*5, 255, LINEARBLEND); // * beatsin(5, -1000, 1000)/1000
- }
- if(col < stungus && col > gungus){
- CRGBPalette16 palmid = blackwhite;
- leds[col][x] = ColorFromPalette(palmid, rowcount + x*5, 255, LINEARBLEND);
- }
- }
- leds[stungus][x] = CHSV(255, 0, 0); // Write wave position
- leds[gungus][x] = CHSV(255, 0, 0);
- }
- count++;
- rowcount = rowcount - beatsin8(20, 1, 7);
- hue = hue + beatsin8(10, 1, 6);
- }
- void visualizer(){
- bool newReading = MSGEQ7.read(EQ7interval); // Look for new reading (can remove if delay)
- if (newReading) {
- FastLED.clear();
- for(int s = 0; s < 7; s++){ // For each fq
- uint8_t fq = MSGEQ7.get(s); // Get reading
- fq = mapNoise(fq, nz, 255, 0, 255); // Reduce noise
- EQ7avg[s] = EQ7avg[s] * 0.95 + fq * 0.05; // Moving Average
- fq = map(fq, 0, round(EQ7avg[s]), 0, LEDper); // Scale values to length of strips
- // Write values to LEDs
- for(int leng = 0; leng < fq; leng++){ // Display as 00 11 22 33 44 55 66 66 55 44 33 22 11 00
- leds[s*2][leng] = CHSV(hue+leng*5, 255, 255);
- leds[1 + s*2][leng] = CHSV(hue+leng*5, 255, 255);
- leds[LEDstrips-1-s*2][leng] = CHSV(hue+leng*5, 255, 255);
- leds[LEDstrips-2-s*2][leng] = CHSV(hue+leng*5, 255, 255);
- }
- // Peak detection
- if( fq == 0 ){
- } else if (round(EQ7peak[s]) > fq){
- EQ7peak[s] = EQ7peak[s] * 0.9; // can multiply to make exponential
- leds[s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
- leds[1 + s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
- leds[LEDstrips-1-s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
- leds[LEDstrips-2-s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
- } else {
- EQ7peak[s] = fq;
- leds[s*2][fq] = CHSV(hue, 0, 255);
- leds[1 + s*2][fq] = CHSV(hue, 0, 255);
- leds[LEDstrips-1-s*2][fq] = CHSV(hue, 0, 255);
- leds[LEDstrips-2-s*2][fq] = CHSV(hue, 0, 255);
- }
- }
- // Beat Action
- if(MSGEQ7.get(1) > 20*EQ7avg[1]){ // could put this in s loop and flash the individual strips or make it be the first 3 bands
- for(int x = 0; x < LEDstrips; x++){
- fill_solid (leds[x], LEDper, CRGB(255, 255, 255));
- }
- }
- }
- }
- void snow(){
- for(byte i = 0; i < LEDstrips; i++){ // Fade everything
- leds[i].fadeToBlackBy( 64 );
- }
- for (int x = 0; x < colcount; x++){ // columns
- for (int y = 0; y < rowcount; y++){ // rows
- for(int i = 0; i < (rowcount+colcount)/3; i++){ // paint lights proportional to how much of the display is being updated
- leds[x][random8(LEDper)] = CHSV( random8(), random8(), 255); // consider having these paint from inside out, instead of outside in
- leds[LEDstrips-1-x][random8(LEDper)] = CHSV( random8(), random8(), 255); // doubled for symmetry
- }
- }
- }
- // Roll counters forward and wrap at boundaries
- rowcount++;
- colcount++;
- if(colcount == LEDstrips/2){
- colcount = 0;
- }
- if(rowcount == LEDper){
- rowcount = 0;
- }
- }
- void initialization(){
- CRGBPalette16 PALstart = startup;
- for(int y = 0; y < LEDper; y++){ //read original values from array and add hue mod
- for(int x = 0; x < LEDstrips; x++){
- uint8_t data = pgm_read_byte_near(&startarray[y*LEDstrips+x]; // Get map value
- if(data == 2){ //red // Colour according to map value
- leds[x][y] = ColorFromPalette( PALstart, 0+hue+abs(13-x), NOBLEND);
- } else if(data == 3){ //yellow
- leds[x][y] = ColorFromPalette( PALstart, 51+hue+abs(13-x), NOBLEND);
- } else if(data == 4){ //green
- leds[x][y] = ColorFromPalette( PALstart, 102+hue+abs(13-x), NOBLEND);
- } else if(data == 5){ //cyan
- leds[x][y] = ColorFromPalette( PALstart, 153+hue+abs(13-x), NOBLEND);
- } else if(data == 6){ //blue
- leds[x][y] = ColorFromPalette( PALstart, 204+hue+abs(13-x), NOBLEND);
- } else if(data == 1){ //white
- leds[x][y] = CHSV(255, 0, 255);
- } else { //black
- leds[x][y] = CHSV(0, 0, 0);
- }
- }
- }
- hue++;
- }
- void seanbox(){ //rowcount and colcount must be 1 instead of 0 to avoid divide-by-zero
- for (int col = 0; col < colcount; col++){
- for(int row = 0; row < rowcount; row++){
- int x = col;
- int y = row % (2*colcount); //distance from top of pattern
- int y2 = (2*colcount)-1 - y; //distance from bottom of pattern
- if (y < y2) { //pattern moves right
- if(x > y ){
- leds[col][row] = CHSV(hue+(row + x - y)*15, 255, 255);
- }
- else {
- leds[col][row] = CHSV(hue+row*15, 255, 255);
- }
- }
- else //pattern moves left
- {
- if(x > y2){
- leds[col][row] = CHSV(hue+(row + y2 - x)*15, 255, 255);
- }
- else {
- leds[col][row] = CHSV(hue+row*15, 255, 255);
- }
- }
- }
- }
- hue = hue + 11;
- count = (count+1)%10; //cycle through 10 numbers
- if (count == 0) { //every 10 iterations, do this
- if(rowcount < LEDper){rowcount++;}
- if(colcount < LEDstrips){colcount++;}
- }
- }
- RainbowColors_p;
- RainbowStripeColors_p;
- CloudColors_p;
- PartyColors_p;
- LavaColors_p;
- OceanColors_p;
- ForestColors_p;
- HeatColors_p;
- /*
- void paletteknife(){
- uint8_t BLEpalette[20]; // goes up top // Needs to be 4 times however many colors are being used.
- hsv = CHSV(random8(), 255, 255); // pick random hue
- hsv2rgb_rainbow( hsv, rgb); // convert to R,G,B
- for(byte x = 0; X < BLEsecondary; x++){
- strtokIndx = strtok(NULL, ",");
- palettedata[x] = atoi(strtokIndx);
- }
- dynamicpal = palettedata;
- }
- void BLEparse() {
- char * strtokIndx; // this is used by strtok() as an index
- strtokIndx = strtok(BLEtempchars,","); // get the first part - the string
- strcpy(BLEprimary, strtokIndx); // copy it to messageFromPC
- strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
- BLEsecondary = atoi(strtokIndx); // convert this part to an integer
- for(byte x = 0; X < BLEsecondary; x++){
- strtokIndx = strtok(NULL, ",");
- BLEpalette[x] = atoi(strtokIndx);
- }
- }
- else if (strcmp(BLEprimary, "Palette") == 0){
- dynamicpal = BLEpalette;
- }
- void waterfall(){
- for (int row = 0; row < rowcount/2; row++){
- for (int col = 0; col < LEDstrips; col++){ // Write each row with start colour and a random saturation
- leds[col][row] = CHSV(hue + row*5, 255, 255); //random(155,255)
- }
- }
- hue = hue - 4;
- FastLED.show();
- if(rowcount/2 < LEDper){
- rowcount++;
- }
- }
- */
- // Adjust start pal colour locations
- // make seanbox move faster
- // adjust power switch (just make it go to default amps
- // update random numbers -> random8(n) random from 0 to n-1
- // random8() == random from 0..255
- // random8( n) == random from 0..(N-1)
- // random8( n, m) == random from N..(M-1)
- //switch snow function to fade to black by (20)
- //HSV color ramp: blue purple ping red orange yellow (and back) Basically, everything but the greens, which tend to make people's skin look unhealthy.
- // on initialization, change to no blend
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement