/ GemmaM0_Band_Jacket / DiscoBandCamp / DiscoBandCamp.ino
DiscoBandCamp.ino
  1  // SPDX-FileCopyrightText: 2019 Amelia T
  2  //
  3  // SPDX-License-Identifier: MIT
  4  
  5  //    Sketch for "DiscoBandCamp" by Amelia T, 2019
  6  //    See Adafruit guide & XYmap.h for pixel map for more information
  7  //    Use Adafruit Gemma M0: 60 pixels to D0, 60 pixels to D1, & button to D2 & GND
  8  //
  9  //    This sketch shows mapping pixels on an irregular matrix and provides 
 10  //    various examples from RGB Shades Demo Code & the FastLED demo library.
 11  //    Can easily incorporate other examples or create your own!
 12  //    
 13  //    To use:
 14  //    Press the button to cycle through available effects shown on the functions list
 15  //    Press and hold the button (>one second) to cycle through five brightness levels
 16  //   
 17  //    Special credit to RGB Shades Demo Code Copyright (c) 2015 macetech LLC
 18  //    This software is provided under the MIT License (see license.txt)
 19  //    Special credit to Mark Kriegsman for XY mapping code
 20  
 21  
 22  //  Pins on Adafruit Gemma M0
 23  #define LEFT_PIN    1     // Visual Left (LEDs on the wearers right) connected to D1
 24  #define NUM_LEFT    60    // number of LEDs connected on the Left
 25  #define RIGHT_PIN   0     // Visual Right (LEDs on the wearers left) connected to D0
 26  #define NUM_RIGHT   60    // number of LEDs connected on the Right
 27  
 28  //  Color order (Green/Red/Blue)
 29  #define COLOR_ORDER GRB
 30  #define CHIPSET     WS2812B
 31  
 32  //  Global maximum brightness value, maximum 255
 33  #define MAXBRIGHTNESS 100
 34  #define STARTBRIGHTNESS 32
 35  
 36  //  Hue time (milliseconds between hue increments)
 37  #define hueTime 30
 38  
 39  // Include FastLED library and other useful files
 40  #include <FastLED.h>
 41  #include "XYmap.h"
 42  #include "utils.h"
 43  #include "effects.h"
 44  #include "buttons.h"
 45  
 46  // list of Functions:
 47  functionList effectList[] = {SolidRed,    //all pixels solid red
 48                               swirly,      //glittery swirly patterns
 49                               NoisePlusPalette,   //NoisePlusPalette fastLED example sketch
 50                               confetti,    //confetti with a random FastLED palette
 51                               threeSine,   //Triple Sine Waves
 52                               colorFill,   // Fills saturated colors into the array from alternating directions
 53                               plasma,      //pretty rainbow plasma animation
 54                               rider,       //Scanning pattern left/right, using global hue cycle
 55                               myConfetti,  //confetti in with my pink/orange palette
 56                               slantBars,   //slanted bars
 57                               sideRain,    // Random pixels scroll sideways, using current hue
 58                               SolidWhite,  //all pixels solid white, great for portopotty visits!       
 59                              };
 60  
 61  const byte numEffects = (sizeof(effectList)/sizeof(effectList[0]));
 62  
 63  // Runs one time at the start of the program (power up or reset)
 64  void setup() {
 65  
 66  //Add the onboard Strip on the Right and Left to create a single array
 67    FastLED.addLeds<CHIPSET, LEFT_PIN, COLOR_ORDER>(leds, 0, NUM_LEFT);
 68    FastLED.addLeds<CHIPSET, RIGHT_PIN, COLOR_ORDER>(leds, NUM_LEFT, NUM_RIGHT);
 69  
 70    // set global brightness value
 71    FastLED.setBrightness( scale8(currentBrightness, MAXBRIGHTNESS) );
 72  
 73    // configure input buttons
 74    pinMode(MODEBUTTON, INPUT_PULLUP);
 75  }
 76  
 77  
 78  // Runs over and over until power off or reset
 79  void loop()
 80  {
 81    currentMillis = millis(); // save the current timer value
 82    updateButtons();          // read, debounce, and process the buttons
 83    doButtons();              // perform actions based on button state
 84  
 85    // increment the global hue value every hueTime milliseconds
 86    if (currentMillis - hueMillis > hueTime) {
 87      hueMillis = currentMillis;
 88      hueCycle(1); // increment the global hue value
 89    }
 90  
 91    // run the currently selected effect every effectDelay milliseconds
 92    if (currentMillis - effectMillis > effectDelay) {
 93      effectMillis = currentMillis;
 94      effectList[currentEffect](); // run the selected effect function
 95      random16_add_entropy(1); // make the random values a bit more random-ish
 96    }
 97  
 98    // run a fade effect too if the confetti or myConfetti is running:
 99    if (effectList[currentEffect] == confetti or myConfetti) fadeAll(1);
100  
101    FastLED.show(); // send the contents of the led memory to the LEDs
102  }