Skip to content

Commit f3c774b

Browse files
authored
Add files via upload
1 parent 1fa6169 commit f3c774b

File tree

5 files changed

+778
-0
lines changed

5 files changed

+778
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
#if defined(FASTLED_VERSION) && FASTLED_VERSION > 3010001
47+
#error "FastLED 3.10.2 has known compile issues with SAMD boards. Please downgrade to FastLED 3.10.1"
48+
#endif
49+
50+
// list of Functions:
51+
functionList effectList[] = {SolidRed, //all pixels solid red
52+
swirly, //glittery swirly patterns
53+
NoisePlusPalette, //NoisePlusPalette fastLED example sketch
54+
confetti, //confetti with a random FastLED palette
55+
threeSine, //Triple Sine Waves
56+
colorFill, // Fills saturated colors into the array from alternating directions
57+
plasma, //pretty rainbow plasma animation
58+
rider, //Scanning pattern left/right, using global hue cycle
59+
myConfetti, //confetti in with my pink/orange palette
60+
slantBars, //slanted bars
61+
sideRain, // Random pixels scroll sideways, using current hue
62+
SolidWhite, //all pixels solid white, great for portopotty visits!
63+
};
64+
65+
const byte numEffects = (sizeof(effectList)/sizeof(effectList[0]));
66+
67+
// Runs one time at the start of the program (power up or reset)
68+
void setup() {
69+
70+
//Add the onboard Strip on the Right and Left to create a single array
71+
FastLED.addLeds<CHIPSET, LEFT_PIN, COLOR_ORDER>(leds, 0, NUM_LEFT);
72+
FastLED.addLeds<CHIPSET, RIGHT_PIN, COLOR_ORDER>(leds, NUM_LEFT, NUM_RIGHT);
73+
74+
// set global brightness value
75+
FastLED.setBrightness( scale8(currentBrightness, MAXBRIGHTNESS) );
76+
77+
// configure input buttons
78+
pinMode(MODEBUTTON, INPUT_PULLUP);
79+
}
80+
81+
82+
// Runs over and over until power off or reset
83+
void loop()
84+
{
85+
currentMillis = millis(); // save the current timer value
86+
updateButtons(); // read, debounce, and process the buttons
87+
doButtons(); // perform actions based on button state
88+
89+
// increment the global hue value every hueTime milliseconds
90+
if (currentMillis - hueMillis > hueTime) {
91+
hueMillis = currentMillis;
92+
hueCycle(1); // increment the global hue value
93+
}
94+
95+
// run the currently selected effect every effectDelay milliseconds
96+
if (currentMillis - effectMillis > effectDelay) {
97+
effectMillis = currentMillis;
98+
effectList[currentEffect](); // run the selected effect function
99+
random16_add_entropy(1); // make the random values a bit more random-ish
100+
}
101+
102+
// run a fade effect too if the confetti or myConfetti is running:
103+
if (effectList[currentEffect] == confetti or myConfetti) fadeAll(1);
104+
105+
FastLED.show(); // send the contents of the led memory to the LEDs
106+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// Helper functions for a two-dimensional XY matrix of pixels.
6+
// Special credit to Mark Kriegsman for RGB Shades Kickstarter 2014-10-18
7+
// https://www.kickstarter.com/projects/macetech/rgb-led-shades
8+
//
9+
// This special 'XY' code lets you program as a plain matrix.
10+
//
11+
// Writing to and reading from the 'holes' in the layout is
12+
// also allowed; holes retain their data, it's just not displayed.
13+
//
14+
// You can also test to see if you're on or off the layout
15+
// like this
16+
// if( XY(x,y) > LAST_VISIBLE_LED ) { ...off the layout...}
17+
//
18+
// X and Y bounds checking is also included, so it is safe
19+
// to just do this without checking x or y in your code:
20+
// leds[ XY(x,y) ] == CRGB::Red;
21+
// All out of bounds coordinates map to the first hidden pixel.
22+
//
23+
// XY(x,y) takes x and y coordinates and returns an LED index number,
24+
// for use like this: leds[ XY(x,y) ] == CRGB::Red;
25+
26+
#include <FastLED.h>
27+
28+
// Parameters for width and height
29+
const uint8_t kMatrixWidth = 24;
30+
const uint8_t kMatrixHeight = 8;
31+
const uint8_t kBorderWidth = 2; //for swirly
32+
33+
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
34+
CRGB leds[ NUM_LEDS ];
35+
36+
// This function will return the right 'led index number' for
37+
// a given set of X and Y coordinates on DiscoBandCamp
38+
// This code, plus the supporting 80-byte table is much smaller
39+
// and much faster than trying to calculate the pixel ID with code.
40+
#define LAST_VISIBLE_LED 119
41+
uint16_t XY(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
42+
{
43+
(void)width;
44+
(void)height;
45+
// any out of bounds address maps to the first hidden pixel
46+
if( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
47+
return (LAST_VISIBLE_LED + 1);
48+
}
49+
50+
// On the visual left of DiscoBandCamp, wearers right
51+
// +------------------------------------------
52+
// | 10 9 8 7 6 5 4 3 2 1 0
53+
// | . 20 19 18 17 16 15 14 13 12 11
54+
// | . . 29 28 27 26 25 24 23 22 21
55+
// | . . . 37 36 35 34 33 32 31 30
56+
// | . . . . 44 43 42 41 40 39 38
57+
// | . . . . . 50 49 48 47 46 45
58+
// | . . . . . . 55 54 53 52 51
59+
// | . . . . . . . 59 58 57 56
60+
61+
//this is how DiscoBandCamp works
62+
const uint8_t JacketTable[] = {
63+
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 145,
64+
153,60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
65+
120,11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 146,
66+
154,80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 182,
67+
121,127,21, 22, 23, 24, 25, 26, 27, 28, 29, 147,
68+
155,89, 88, 87, 86, 85, 84, 83, 82, 81, 176,183,
69+
122,128,133,30, 31, 32, 33, 34, 35, 36, 37, 148,
70+
156,97, 96, 95, 94, 93, 92, 91, 90, 171,177,184,
71+
123,129,134,135,38, 39, 40, 41, 42, 43, 44, 149,
72+
157,104,103,102,101,100,99, 98, 167,172,178,185,
73+
124,130,134,136,139,45, 46, 47, 48, 49, 50, 150,
74+
158,110,109,108,107,106,105,164,168,173,179,186,
75+
125,131,134,137,140,142,51, 52, 53, 54, 55, 151,
76+
159,115,114,113,112,111,162,165,169,174,180,187,
77+
126,132,134,138,141,143,144,56, 57, 58, 59, 152,
78+
160,119,118,117,116,161,163,166,170,175,181,188,
79+
};
80+
81+
uint8_t i = (y * kMatrixWidth) + x;
82+
uint8_t j = JacketTable[i];
83+
return j;
84+
}
85+
86+
// Instantiate an XYMap object
87+
fl::XYMap myXYMap = fl::XYMap::constructWithUserFunction(kMatrixWidth, kMatrixHeight, XY);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// Process button input and return button activity
6+
// Retained button code from RGB Shades though just using one button
7+
8+
#define NUMBUTTONS 1
9+
#define MODEBUTTON 2 //define the pin the button is connected to
10+
11+
#define BTNIDLE 0
12+
#define BTNDEBOUNCING 1
13+
#define BTNPRESSED 2
14+
#define BTNRELEASED 3
15+
#define BTNLONGPRESS 4
16+
#define BTNLONGPRESSREAD 5
17+
18+
#define BTNDEBOUNCETIME 20
19+
#define BTNLONGPRESSTIME 1000
20+
21+
unsigned long buttonEvents[NUMBUTTONS];
22+
byte buttonStatuses[NUMBUTTONS];
23+
byte buttonmap[NUMBUTTONS] = {MODEBUTTON};
24+
25+
void updateButtons() {
26+
for (byte i = 0; i < NUMBUTTONS; i++) {
27+
switch (buttonStatuses[i]) {
28+
case BTNIDLE:
29+
if (digitalRead(buttonmap[i]) == LOW) {
30+
buttonEvents[i] = currentMillis;
31+
buttonStatuses[i] = BTNDEBOUNCING;
32+
}
33+
break;
34+
35+
case BTNDEBOUNCING:
36+
if (currentMillis - buttonEvents[i] > BTNDEBOUNCETIME) {
37+
if (digitalRead(buttonmap[i]) == LOW) {
38+
buttonStatuses[i] = BTNPRESSED;
39+
}
40+
}
41+
break;
42+
43+
case BTNPRESSED:
44+
if (digitalRead(buttonmap[i]) == HIGH) {
45+
buttonStatuses[i] = BTNRELEASED;
46+
} else if (currentMillis - buttonEvents[i] > BTNLONGPRESSTIME) {
47+
buttonStatuses[i] = BTNLONGPRESS;
48+
}
49+
break;
50+
51+
case BTNRELEASED:
52+
break;
53+
54+
case BTNLONGPRESS:
55+
break;
56+
57+
case BTNLONGPRESSREAD:
58+
if (digitalRead(buttonmap[i]) == HIGH) {
59+
buttonStatuses[i] = BTNIDLE;
60+
}
61+
break;
62+
}
63+
}
64+
}
65+
66+
byte buttonStatus(byte buttonNum) {
67+
68+
byte tempStatus = buttonStatuses[buttonNum];
69+
if (tempStatus == BTNRELEASED) {
70+
buttonStatuses[buttonNum] = BTNIDLE;
71+
} else if (tempStatus == BTNLONGPRESS) {
72+
buttonStatuses[buttonNum] = BTNLONGPRESSREAD;
73+
}
74+
75+
return tempStatus;
76+
77+
}
78+
79+
// Check the mode button (for switching between effects)
80+
void doButtons() {
81+
switch (buttonStatus(0)) {
82+
83+
case BTNRELEASED: // short button press
84+
cycleMillis = currentMillis;
85+
if (++currentEffect >= numEffects) currentEffect = 0; // loop to start of effect list
86+
effectInit = false; // trigger effect initialization when new effect is selected
87+
break;
88+
89+
case BTNLONGPRESS: // long button press
90+
currentBrightness += 51; // increase the brightness (wraps to lowest)
91+
FastLED.setBrightness(scale8(currentBrightness, MAXBRIGHTNESS));
92+
break;
93+
}
94+
}

0 commit comments

Comments
 (0)