From d9ce978dc7f606274aa4dc3f284a0a706eabddfe Mon Sep 17 00:00:00 2001 From: Liz Date: Mon, 18 Nov 2024 12:06:58 -0500 Subject: [PATCH] switch to constructWithUserFunction --- .../DiscoBandCamp/DiscoBandCamp.ino | 7 ++-- GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h | 6 ++-- GemmaM0_Band_Jacket/DiscoBandCamp/buttons.h | 3 +- GemmaM0_Band_Jacket/DiscoBandCamp/effects.h | 32 +++++++++---------- GemmaM0_Band_Jacket/DiscoBandCamp/utils.h | 4 +-- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/GemmaM0_Band_Jacket/DiscoBandCamp/DiscoBandCamp.ino b/GemmaM0_Band_Jacket/DiscoBandCamp/DiscoBandCamp.ino index 828d99035..06270273c 100644 --- a/GemmaM0_Band_Jacket/DiscoBandCamp/DiscoBandCamp.ino +++ b/GemmaM0_Band_Jacket/DiscoBandCamp/DiscoBandCamp.ino @@ -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) @@ -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(leds, 0, NUM_LEFT); FastLED.addLeds(leds, NUM_LEFT, NUM_RIGHT); diff --git a/GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h b/GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h index 9f6228cae..1355be492 100644 --- a/GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h +++ b/GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h @@ -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); @@ -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); diff --git a/GemmaM0_Band_Jacket/DiscoBandCamp/buttons.h b/GemmaM0_Band_Jacket/DiscoBandCamp/buttons.h index d756d6f17..b8dce971a 100644 --- a/GemmaM0_Band_Jacket/DiscoBandCamp/buttons.h +++ b/GemmaM0_Band_Jacket/DiscoBandCamp/buttons.h @@ -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 diff --git a/GemmaM0_Band_Jacket/DiscoBandCamp/effects.h b/GemmaM0_Band_Jacket/DiscoBandCamp/effects.h index 1dba49f93..d72f53196 100644 --- a/GemmaM0_Band_Jacket/DiscoBandCamp/effects.h +++ b/GemmaM0_Band_Jacket/DiscoBandCamp/effects.h @@ -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); } } @@ -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); } } @@ -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; } } @@ -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]; } } @@ -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]; } } @@ -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); } @@ -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); } } @@ -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); } @@ -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)); } } @@ -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(); } diff --git a/GemmaM0_Band_Jacket/DiscoBandCamp/utils.h b/GemmaM0_Band_Jacket/DiscoBandCamp/utils.h index 4891c342f..b41f5b7ed 100644 --- a/GemmaM0_Band_Jacket/DiscoBandCamp/utils.h +++ b/GemmaM0_Band_Jacket/DiscoBandCamp/utils.h @@ -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)]; } } @@ -177,7 +177,7 @@ void mapNoiseToLEDsUsingPalette() } CRGB color = ColorFromPalette( currentPalette, index, bri); - leds[XY(i,j)] = color; + leds[XY(i,j,0,0)] = color; } }