Skip to content

Commit

Permalink
switch to constructWithUserFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
BlitzCityDIY committed Nov 18, 2024
1 parent 025eace commit d9ce978
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
7 changes: 4 additions & 3 deletions GemmaM0_Band_Jacket/DiscoBandCamp/DiscoBandCamp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@


// Pins on Adafruit Gemma M0
#define LEFT_PIN 1 // Visual Left (LEDs on the wearers right) connected to D1
#define LEFT_PIN PIN_EXTERNAL_NEOPIXELS // Visual Left (LEDs on the wearers right) connected to D1
#define NUM_LEFT 60 // number of LEDs connected on the Left
#define RIGHT_PIN 0 // Visual Right (LEDs on the wearers left) connected to D0
#define RIGHT_PIN 4 // Visual Right (LEDs on the wearers left) connected to D0
#define NUM_RIGHT 60 // number of LEDs connected on the Right

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

// Runs one time at the start of the program (power up or reset)
void setup() {

pinMode(PIN_EXTERNAL_POWER, OUTPUT);
digitalWrite(PIN_EXTERNAL_POWER, HIGH);
//Add the onboard Strip on the Right and Left to create a single array
FastLED.addLeds<CHIPSET, LEFT_PIN, COLOR_ORDER>(leds, 0, NUM_LEFT);
FastLED.addLeds<CHIPSET, RIGHT_PIN, COLOR_ORDER>(leds, NUM_LEFT, NUM_RIGHT);
Expand Down
6 changes: 4 additions & 2 deletions GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ CRGB leds[ NUM_LEDS ];
// This code, plus the supporting 80-byte table is much smaller
// and much faster than trying to calculate the pixel ID with code.
#define LAST_VISIBLE_LED 119
uint8_t XY( uint8_t x, uint8_t y)
uint16_t XY(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
(void)width;
(void)height;
// any out of bounds address maps to the first hidden pixel
if( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
return (LAST_VISIBLE_LED + 1);
Expand Down Expand Up @@ -82,4 +84,4 @@ uint8_t XY( uint8_t x, uint8_t y)
}

// Instantiate an XYMap object
XYMap myXYMap(kMatrixWidth, kMatrixHeight);
XYMap myXYMap = XYMap::constructWithUserFunction(kMatrixWidth, kMatrixHeight, XY);
3 changes: 1 addition & 2 deletions GemmaM0_Band_Jacket/DiscoBandCamp/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
// Retained button code from RGB Shades though just using one button

#define NUMBUTTONS 1
#define MODEBUTTON 2 //define the pin the button is connected to

#define MODEBUTTON PIN_EXTERNAL_BUTTON //define the pin the button is connected to
#define BTNIDLE 0
#define BTNDEBOUNCING 1
#define BTNPRESSED 2
Expand Down
32 changes: 16 additions & 16 deletions GemmaM0_Band_Jacket/DiscoBandCamp/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void threeSine() {
byte sinDistanceG = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 10 + x * 16)), 2);
byte sinDistanceB = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 11 + x * 16)), 2);

leds[XY(x, y)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB);
leds[XY(x, y, 0, 0)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB);
}
}

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

Expand Down Expand Up @@ -100,7 +100,7 @@ void rider() {
brightness = 255 - brightness;
CRGB riderColor = CHSV(cycleHue, 255, brightness);
for (byte y = 0; y < kMatrixHeight; y++) {
leds[XY(x, y)] = riderColor;
leds[XY(x, y, 0, 0)] = riderColor;
}
}

Expand Down Expand Up @@ -133,7 +133,7 @@ void colorFill() {
for (byte x = 0; x < kMatrixWidth; x++) {
byte y = currentRow;
if (currentDirection == 2) y = kMatrixHeight - 1 - currentRow;
leds[XY(x, y)] = currentPalette[currentColor];
leds[XY(x, y, 0, 0)] = currentPalette[currentColor];
}
}

Expand All @@ -143,7 +143,7 @@ void colorFill() {
for (byte y = 0; y < kMatrixHeight; y++) {
byte x = currentRow;
if (currentDirection == 3) x = kMatrixWidth - 1 - currentRow;
leds[XY(x, y)] = currentPalette[currentColor];
leds[XY(x, y, 0, 0)] = currentPalette[currentColor];
}
}

Expand Down Expand Up @@ -174,8 +174,8 @@ void sideRain() {

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

}

Expand All @@ -194,7 +194,7 @@ void confetti() {

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

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

Expand Down Expand Up @@ -263,7 +263,7 @@ void slantBars() {

for (byte x = 0; x < kMatrixWidth; x++) {
for (byte y = 0; y < kMatrixHeight; y++) {
leds[XY(x, y)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos));
leds[XY(x, y, 0, 0)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos));
}
}

Expand Down Expand Up @@ -297,12 +297,12 @@ void swirly()

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

FastLED.show();
}
4 changes: 2 additions & 2 deletions GemmaM0_Band_Jacket/DiscoBandCamp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void scrollArray(byte scrollDir) {
}

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

Expand Down Expand Up @@ -177,7 +177,7 @@ void mapNoiseToLEDsUsingPalette()
}

CRGB color = ColorFromPalette( currentPalette, index, bri);
leds[XY(i,j)] = color;
leds[XY(i,j,0,0)] = color;
}
}

Expand Down

0 comments on commit d9ce978

Please sign in to comment.