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