Skip to content

Commit 4e72f9d

Browse files
committed
Merge remote-tracking branch 'adafruit/master' into mindsweep
2 parents d745df8 + 1bcc622 commit 4e72f9d

7 files changed

Lines changed: 774 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Helper functions for a two-dimensional XY matrix of pixels.
2+
// Special credit to Mark Kriegsman for RGB Shades Kickstarter 2014-10-18
3+
// https://www.kickstarter.com/projects/macetech/rgb-led-shades
4+
//
5+
// This special 'XY' code lets you program as a plain matrix.
6+
//
7+
// Writing to and reading from the 'holes' in the layout is
8+
// also allowed; holes retain their data, it's just not displayed.
9+
//
10+
// You can also test to see if you're on or off the layout
11+
// like this
12+
// if( XY(x,y) > LAST_VISIBLE_LED ) { ...off the layout...}
13+
//
14+
// X and Y bounds checking is also included, so it is safe
15+
// to just do this without checking x or y in your code:
16+
// leds[ XY(x,y) ] == CRGB::Red;
17+
// All out of bounds coordinates map to the first hidden pixel.
18+
//
19+
// XY(x,y) takes x and y coordinates and returns an LED index number,
20+
// for use like this: leds[ XY(x,y) ] == CRGB::Red;
21+
22+
23+
// Parameters for width and height
24+
const uint8_t kMatrixWidth = 24;
25+
const uint8_t kMatrixHeight = 8;
26+
const uint8_t kBorderWidth = 2; //for swirly
27+
28+
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
29+
CRGB leds[ NUM_LEDS ];
30+
31+
// This function will return the right 'led index number' for
32+
// a given set of X and Y coordinates on DiscoBandCamp
33+
// This code, plus the supporting 80-byte table is much smaller
34+
// and much faster than trying to calculate the pixel ID with code.
35+
#define LAST_VISIBLE_LED 119
36+
uint8_t XY( uint8_t x, uint8_t y)
37+
{
38+
// any out of bounds address maps to the first hidden pixel
39+
if( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
40+
return (LAST_VISIBLE_LED + 1);
41+
}
42+
43+
// On the visual left of DiscoBandCamp, wearers right
44+
// +------------------------------------------
45+
// | 10 9 8 7 6 5 4 3 2 1 0
46+
// | . 20 19 18 17 16 15 14 13 12 11
47+
// | . . 29 28 27 26 25 24 23 22 21
48+
// | . . . 37 36 35 34 33 32 31 30
49+
// | . . . . 44 43 42 41 40 39 38
50+
// | . . . . . 50 49 48 47 46 45
51+
// | . . . . . . 55 54 53 52 51
52+
// | . . . . . . . 59 58 57 56
53+
54+
//this is how DiscoBandCamp works
55+
const uint8_t JacketTable[] = {
56+
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 145,
57+
153,60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
58+
120,11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 146,
59+
154,80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 182,
60+
121,127,21, 22, 23, 24, 25, 26, 27, 28, 29, 147,
61+
155,89, 88, 87, 86, 85, 84, 83, 82, 81, 176,183,
62+
122,128,133,30, 31, 32, 33, 34, 35, 36, 37, 148,
63+
156,97, 96, 95, 94, 93, 92, 91, 90, 171,177,184,
64+
123,129,134,135,38, 39, 40, 41, 42, 43, 44, 149,
65+
157,104,103,102,101,100,99, 98, 167,172,178,185,
66+
124,130,134,136,139,45, 46, 47, 48, 49, 50, 150,
67+
158,110,109,108,107,106,105,164,168,173,179,186,
68+
125,131,134,137,140,142,51, 52, 53, 54, 55, 151,
69+
159,115,114,113,112,111,162,165,169,174,180,187,
70+
126,132,134,138,141,143,144,56, 57, 58, 59, 152,
71+
160,119,118,117,116,161,163,166,170,175,181,188,
72+
};
73+
74+
uint8_t i = (y * kMatrixWidth) + x;
75+
uint8_t j = JacketTable[i];
76+
return j;
77+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Process button input and return button activity
2+
// Retained button code from RGB Shades though just using one button
3+
4+
#define NUMBUTTONS 1
5+
#define MODEBUTTON 2 //define the pin the button is connected to
6+
7+
#define BTNIDLE 0
8+
#define BTNDEBOUNCING 1
9+
#define BTNPRESSED 2
10+
#define BTNRELEASED 3
11+
#define BTNLONGPRESS 4
12+
#define BTNLONGPRESSREAD 5
13+
14+
#define BTNDEBOUNCETIME 20
15+
#define BTNLONGPRESSTIME 1000
16+
17+
unsigned long buttonEvents[NUMBUTTONS];
18+
byte buttonStatuses[NUMBUTTONS];
19+
byte buttonmap[NUMBUTTONS] = {MODEBUTTON};
20+
21+
void updateButtons() {
22+
for (byte i = 0; i < NUMBUTTONS; i++) {
23+
switch (buttonStatuses[i]) {
24+
case BTNIDLE:
25+
if (digitalRead(buttonmap[i]) == LOW) {
26+
buttonEvents[i] = currentMillis;
27+
buttonStatuses[i] = BTNDEBOUNCING;
28+
}
29+
break;
30+
31+
case BTNDEBOUNCING:
32+
if (currentMillis - buttonEvents[i] > BTNDEBOUNCETIME) {
33+
if (digitalRead(buttonmap[i]) == LOW) {
34+
buttonStatuses[i] = BTNPRESSED;
35+
}
36+
}
37+
break;
38+
39+
case BTNPRESSED:
40+
if (digitalRead(buttonmap[i]) == HIGH) {
41+
buttonStatuses[i] = BTNRELEASED;
42+
} else if (currentMillis - buttonEvents[i] > BTNLONGPRESSTIME) {
43+
buttonStatuses[i] = BTNLONGPRESS;
44+
}
45+
break;
46+
47+
case BTNRELEASED:
48+
break;
49+
50+
case BTNLONGPRESS:
51+
break;
52+
53+
case BTNLONGPRESSREAD:
54+
if (digitalRead(buttonmap[i]) == HIGH) {
55+
buttonStatuses[i] = BTNIDLE;
56+
}
57+
break;
58+
}
59+
}
60+
}
61+
62+
byte buttonStatus(byte buttonNum) {
63+
64+
byte tempStatus = buttonStatuses[buttonNum];
65+
if (tempStatus == BTNRELEASED) {
66+
buttonStatuses[buttonNum] = BTNIDLE;
67+
} else if (tempStatus == BTNLONGPRESS) {
68+
buttonStatuses[buttonNum] = BTNLONGPRESSREAD;
69+
}
70+
71+
return tempStatus;
72+
73+
}
74+
75+
// Check the mode button (for switching between effects)
76+
void doButtons() {
77+
switch (buttonStatus(0)) {
78+
79+
case BTNRELEASED: // short button press
80+
cycleMillis = currentMillis;
81+
if (++currentEffect >= numEffects) currentEffect = 0; // loop to start of effect list
82+
effectInit = false; // trigger effect initialization when new effect is selected
83+
break;
84+
85+
case BTNLONGPRESS: // long button press
86+
currentBrightness += 51; // increase the brightness (wraps to lowest)
87+
FastLED.setBrightness(scale8(currentBrightness, MAXBRIGHTNESS));
88+
break;
89+
}
90+
}

0 commit comments

Comments
 (0)