From 7e070d6489f845688616e9d4822e5df62d6078f5 Mon Sep 17 00:00:00 2001 From: Marc Miller Date: Sun, 4 Apr 2021 15:59:45 -0700 Subject: matrix x,y indicies changed back to uint8_t Matrix examples x,y indicies changed back to uint8_t but returned pixel number kept as uint16_t Added "Params for width and height" and "Param for different pixel layouts" comment lines to match other matrix examples. In NoisePlayground changed #define kMatrixWidth to const uint8_t kMatrixWidth to match format in other matrix examples. --- examples/Noise/Noise.ino | 10 ++++++---- examples/NoisePlayground/NoisePlayground.ino | 6 ++++-- examples/NoisePlusPalette/NoisePlusPalette.ino | 3 +++ examples/XYMatrix/XYMatrix.ino | 21 +++++++++++---------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/examples/Noise/Noise.ino b/examples/Noise/Noise.ino index 9b72aaa8..f11d75d7 100644 --- a/examples/Noise/Noise.ino +++ b/examples/Noise/Noise.ino @@ -5,15 +5,17 @@ // // Params for width and height -const uint16_t kMatrixWidth = 16; -const uint16_t kMatrixHeight = 16; +const uint8_t kMatrixWidth = 16; +const uint8_t kMatrixHeight = 16; + #define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight) #define NUM_LEDS (kMatrixWidth * kMatrixHeight) + // Param for different pixel layouts const bool kMatrixSerpentineLayout = true; -uint16_t XY( uint16_t x, uint16_t y) +uint16_t XY( uint8_t x, uint8_t y) { uint16_t i; @@ -24,7 +26,7 @@ uint16_t XY( uint16_t x, uint16_t y) if( kMatrixSerpentineLayout == true) { if( y & 0x01) { // Odd rows run backwards - uint16_t reverseX = (kMatrixWidth - 1) - x; + uint8_t reverseX = (kMatrixWidth - 1) - x; i = (y * kMatrixWidth) + reverseX; } else { // Even rows run forwards diff --git a/examples/NoisePlayground/NoisePlayground.ino b/examples/NoisePlayground/NoisePlayground.ino index a6d09774..6c047324 100644 --- a/examples/NoisePlayground/NoisePlayground.ino +++ b/examples/NoisePlayground/NoisePlayground.ino @@ -1,9 +1,11 @@ #include -#define kMatrixWidth 16 -#define kMatrixHeight 16 +// Params for width and height +const uint8_t kMatrixWidth = 16; +const uint8_t kMatrixHeight = 16; #define NUM_LEDS (kMatrixWidth * kMatrixHeight) + // Param for different pixel layouts #define kMatrixSerpentineLayout true diff --git a/examples/NoisePlusPalette/NoisePlusPalette.ino b/examples/NoisePlusPalette/NoisePlusPalette.ino index c48b2c36..4670cc38 100644 --- a/examples/NoisePlusPalette/NoisePlusPalette.ino +++ b/examples/NoisePlusPalette/NoisePlusPalette.ino @@ -5,8 +5,11 @@ #define LED_TYPE WS2811 #define COLOR_ORDER GRB +// Params for width and height const uint8_t kMatrixWidth = 16; const uint8_t kMatrixHeight = 16; + +// Param for different pixel layouts const bool kMatrixSerpentineLayout = true; diff --git a/examples/XYMatrix/XYMatrix.ino b/examples/XYMatrix/XYMatrix.ino index 4901d697..cce1fbf3 100644 --- a/examples/XYMatrix/XYMatrix.ino +++ b/examples/XYMatrix/XYMatrix.ino @@ -15,7 +15,7 @@ // No error checking is performed on the ranges of x and y. // // XYsafe(x,y) takes x and y coordinates and returns an LED index number, -// for use like this: leds[ XY(x,y) ] == CRGB::Red; +// for use like this: leds[ XYsafe(x,y) ] == CRGB::Red; // Error checking IS performed on the ranges of x and y, and an // index of "-1" is returned. Special instructions below // explain how to use this without having to do your own error @@ -25,12 +25,13 @@ // Params for width and height -const uint16_t kMatrixWidth = 16; -const uint16_t kMatrixHeight = 16; +const uint8_t kMatrixWidth = 16; +const uint8_t kMatrixHeight = 16; // Param for different pixel layouts const bool kMatrixSerpentineLayout = true; const bool kMatrixVertical = false; + // Set 'kMatrixSerpentineLayout' to false if your pixels are // laid out all running the same way, like this: // @@ -74,8 +75,8 @@ const bool kMatrixVertical = false; // // Use the "XY" function like this: // -// for( uint16_t x = 0; x < kMatrixWidth; x++) { -// for( uint16_t y = 0; y < kMatrixHeight; y++) { +// for( uint8_t x = 0; x < kMatrixWidth; x++) { +// for( uint8_t y = 0; y < kMatrixHeight; y++) { // // // Here's the x, y to 'led index' in action: // leds[ XY( x, y) ] = CHSV( random8(), 255, 255); @@ -84,7 +85,7 @@ const bool kMatrixVertical = false; // } // // -uint16_t XY( uint16_t x, uint16_t y) +uint16_t XY( uint8_t x, uint8_t y) { uint16_t i; @@ -100,7 +101,7 @@ uint16_t XY( uint16_t x, uint16_t y) if (kMatrixVertical == false) { if( y & 0x01) { // Odd rows run backwards - uint16_t reverseX = (kMatrixWidth - 1) - x; + uint8_t reverseX = (kMatrixWidth - 1) - x; i = (y * kMatrixWidth) + reverseX; } else { // Even rows run forwards @@ -165,7 +166,7 @@ uint16_t XY( uint16_t x, uint16_t y) CRGB leds_plus_safety_pixel[ NUM_LEDS + 1]; CRGB* const leds( leds_plus_safety_pixel + 1); -uint16_t XYsafe( uint16_t x, uint16_t y) +uint16_t XYsafe( uint8_t x, uint8_t y) { if( x >= kMatrixWidth) return -1; if( y >= kMatrixHeight) return -1; @@ -192,10 +193,10 @@ void loop() void DrawOneFrame( uint8_t startHue8, int8_t yHueDelta8, int8_t xHueDelta8) { uint8_t lineStartHue = startHue8; - for( uint16_t y = 0; y < kMatrixHeight; y++) { + for( uint8_t y = 0; y < kMatrixHeight; y++) { lineStartHue += yHueDelta8; uint8_t pixelHue = lineStartHue; - for( uint16_t x = 0; x < kMatrixWidth; x++) { + for( uint8_t x = 0; x < kMatrixWidth; x++) { pixelHue += xHueDelta8; leds[ XY(x, y)] = CHSV( pixelHue, 255, 255); } -- cgit v1.2.3