Skip to content

Commit d9ce978

Browse files
committed
switch to constructWithUserFunction
1 parent 025eace commit d9ce978

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

GemmaM0_Band_Jacket/DiscoBandCamp/DiscoBandCamp.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121

2222
// Pins on Adafruit Gemma M0
23-
#define LEFT_PIN 1 // Visual Left (LEDs on the wearers right) connected to D1
23+
#define LEFT_PIN PIN_EXTERNAL_NEOPIXELS // Visual Left (LEDs on the wearers right) connected to D1
2424
#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
25+
#define RIGHT_PIN 4 // Visual Right (LEDs on the wearers left) connected to D0
2626
#define NUM_RIGHT 60 // number of LEDs connected on the Right
2727

2828
// Color order (Green/Red/Blue)
@@ -62,7 +62,8 @@ const byte numEffects = (sizeof(effectList)/sizeof(effectList[0]));
6262

6363
// Runs one time at the start of the program (power up or reset)
6464
void setup() {
65-
65+
pinMode(PIN_EXTERNAL_POWER, OUTPUT);
66+
digitalWrite(PIN_EXTERNAL_POWER, HIGH);
6667
//Add the onboard Strip on the Right and Left to create a single array
6768
FastLED.addLeds<CHIPSET, LEFT_PIN, COLOR_ORDER>(leds, 0, NUM_LEFT);
6869
FastLED.addLeds<CHIPSET, RIGHT_PIN, COLOR_ORDER>(leds, NUM_LEFT, NUM_RIGHT);

GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ CRGB leds[ NUM_LEDS ];
3838
// This code, plus the supporting 80-byte table is much smaller
3939
// and much faster than trying to calculate the pixel ID with code.
4040
#define LAST_VISIBLE_LED 119
41-
uint8_t XY( uint8_t x, uint8_t y)
41+
uint16_t XY(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
4242
{
43+
(void)width;
44+
(void)height;
4345
// any out of bounds address maps to the first hidden pixel
4446
if( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
4547
return (LAST_VISIBLE_LED + 1);
@@ -82,4 +84,4 @@ uint8_t XY( uint8_t x, uint8_t y)
8284
}
8385

8486
// Instantiate an XYMap object
85-
XYMap myXYMap(kMatrixWidth, kMatrixHeight);
87+
XYMap myXYMap = XYMap::constructWithUserFunction(kMatrixWidth, kMatrixHeight, XY);

GemmaM0_Band_Jacket/DiscoBandCamp/buttons.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
// Retained button code from RGB Shades though just using one button
77

88
#define NUMBUTTONS 1
9-
#define MODEBUTTON 2 //define the pin the button is connected to
10-
9+
#define MODEBUTTON PIN_EXTERNAL_BUTTON //define the pin the button is connected to
1110
#define BTNIDLE 0
1211
#define BTNDEBOUNCING 1
1312
#define BTNPRESSED 2

GemmaM0_Band_Jacket/DiscoBandCamp/effects.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void threeSine() {
2626
byte sinDistanceG = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 10 + x * 16)), 2);
2727
byte sinDistanceB = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 11 + x * 16)), 2);
2828

29-
leds[XY(x, y)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB);
29+
leds[XY(x, y, 0, 0)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB);
3030
}
3131
}
3232

@@ -70,7 +70,7 @@ void plasma() {
7070
for (int x = 0; x < kMatrixWidth; x++) {
7171
for (int y = 0; y < kMatrixHeight; y++) {
7272
byte color = sin8(sqrt(sq(((float)x - 7.5) * 10 + xOffset - 127) + sq(((float)y - 2) * 10 + yOffset - 127)) + offset);
73-
leds[XY(x, y)] = CHSV(color, 255, 255);
73+
leds[XY(x, y, 0, 0)] = CHSV(color, 255, 255);
7474
}
7575
}
7676

@@ -100,7 +100,7 @@ void rider() {
100100
brightness = 255 - brightness;
101101
CRGB riderColor = CHSV(cycleHue, 255, brightness);
102102
for (byte y = 0; y < kMatrixHeight; y++) {
103-
leds[XY(x, y)] = riderColor;
103+
leds[XY(x, y, 0, 0)] = riderColor;
104104
}
105105
}
106106

@@ -133,7 +133,7 @@ void colorFill() {
133133
for (byte x = 0; x < kMatrixWidth; x++) {
134134
byte y = currentRow;
135135
if (currentDirection == 2) y = kMatrixHeight - 1 - currentRow;
136-
leds[XY(x, y)] = currentPalette[currentColor];
136+
leds[XY(x, y, 0, 0)] = currentPalette[currentColor];
137137
}
138138
}
139139

@@ -143,7 +143,7 @@ void colorFill() {
143143
for (byte y = 0; y < kMatrixHeight; y++) {
144144
byte x = currentRow;
145145
if (currentDirection == 3) x = kMatrixWidth - 1 - currentRow;
146-
leds[XY(x, y)] = currentPalette[currentColor];
146+
leds[XY(x, y, 0, 0)] = currentPalette[currentColor];
147147
}
148148
}
149149

@@ -174,8 +174,8 @@ void sideRain() {
174174

175175
scrollArray(rainDir);
176176
byte randPixel = random8(kMatrixHeight);
177-
for (byte y = 0; y < kMatrixHeight; y++) leds[XY((kMatrixWidth - 1) * rainDir, y)] = CRGB::Black;
178-
leds[XY((kMatrixWidth - 1)*rainDir, randPixel)] = CHSV(cycleHue, 255, 255);
177+
for (byte y = 0; y < kMatrixHeight; y++) leds[XY((kMatrixWidth - 1) * rainDir, y, 0, 0)] = CRGB::Black;
178+
leds[XY((kMatrixWidth - 1)*rainDir, randPixel, 0, 0)] = CHSV(cycleHue, 255, 255);
179179

180180
}
181181

@@ -194,7 +194,7 @@ void confetti() {
194194

195195
// scatter random colored pixels at several random coordinates
196196
for (byte i = 0; i < 4; i++) {
197-
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight))] = ColorFromPalette(currentPalette, random16(255), 255); //CHSV(random16(255), 255, 255);
197+
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight), 0, 0)] = ColorFromPalette(currentPalette, random16(255), 255); //CHSV(random16(255), 255, 255);
198198
random16_add_entropy(1);
199199
}
200200
}
@@ -233,7 +233,7 @@ void myConfetti() {
233233

234234
// scatter random colored pixels at several random coordinates
235235
for (byte i = 0; i < 4; i++) {
236-
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight))] = ColorFromPalette(MyColors_p, random16(255), 255); //CHSV(random16(255), 255, 255);
236+
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight), 0, 0)] = ColorFromPalette(MyColors_p, random16(255), 255); //CHSV(random16(255), 255, 255);
237237
random16_add_entropy(1);
238238
}
239239

@@ -263,7 +263,7 @@ void slantBars() {
263263

264264
for (byte x = 0; x < kMatrixWidth; x++) {
265265
for (byte y = 0; y < kMatrixHeight; y++) {
266-
leds[XY(x, y)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos));
266+
leds[XY(x, y, 0, 0)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos));
267267
}
268268
}
269269

@@ -297,12 +297,12 @@ void swirly()
297297

298298
// The color of each point shifts over time, each at a different speed.
299299
uint16_t ms = millis();
300-
leds[XY( i, j)] += CHSV( ms / 11, 200, 255);
301-
leds[XY( j, i)] += CHSV( ms / 13, 200, 255);
302-
leds[XY(ni,nj)] += CHSV( ms / 17, 200, 255);
303-
leds[XY(nj,ni)] += CHSV( ms / 29, 200, 255);
304-
leds[XY( i,nj)] += CHSV( ms / 37, 200, 255);
305-
leds[XY(ni, j)] += CHSV( ms / 41, 200, 255);
300+
leds[XY(i, j, 0, 0)] += CHSV( ms / 11, 200, 255);
301+
leds[XY(j, i, 0, 0)] += CHSV( ms / 13, 200, 255);
302+
leds[XY(ni,nj, 0, 0)] += CHSV( ms / 17, 200, 255);
303+
leds[XY(nj,ni, 0, 0)] += CHSV( ms / 29, 200, 255);
304+
leds[XY(i,nj, 0, 0)] += CHSV( ms / 37, 200, 255);
305+
leds[XY(ni, j, 0, 0)] += CHSV( ms / 41, 200, 255);
306306

307307
FastLED.show();
308308
}

GemmaM0_Band_Jacket/DiscoBandCamp/utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void scrollArray(byte scrollDir) {
6868
}
6969

7070
for (byte y = 0; y < kMatrixHeight; y++) {
71-
leds[XY(scrollX,y)] = leds[XY(scrollX + scrollDir*2 - 1,y)];
71+
leds[XY(scrollX,y,0,0)] = leds[XY(scrollX + scrollDir*2 - 1,y,0,0)];
7272
}
7373
}
7474

@@ -177,7 +177,7 @@ void mapNoiseToLEDsUsingPalette()
177177
}
178178

179179
CRGB color = ColorFromPalette( currentPalette, index, bri);
180-
leds[XY(i,j)] = color;
180+
leds[XY(i,j,0,0)] = color;
181181
}
182182
}
183183

0 commit comments

Comments
 (0)