diff options
Diffstat (limited to 'examples/XYMatrix/XYMatrix.ino')
-rw-r--r-- | examples/XYMatrix/XYMatrix.ino | 21 |
1 files changed, 11 insertions, 10 deletions
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); } |