0

I am getting this error on compilation of the code given further below;

warning: iteration 3u invokes undefined behavior [-Waggressive-loop-optimizations]

leds[XY (x, y)].r = redarray[x][y];
note: containing loop for(uint8_t x=0; x < MatrixWidth; x++){

Code:

 // the header files for the RGB data

#include <FastLED.h>
#include "redarray.h"   
#include "greenarray.h"   //g data header file (hex or dec)
#include "bluearray.h"   //b data header file (hex or dec)*/

 //matrix parameters

#define MatrixWidth 36 //columns (x)
#define MatrixHeight 1 //rows (y)
#define numled (MatrixWidth * MatrixHeight)

//pin details

#define datapin 7

#define clockpin 8

CRGB leds[MatrixWidth * MatrixHeight];

const bool  MatrixSerpentineLayout = true;

void setup() {

   FastLED.addLeds<APA102, datapin, clockpin>(leds,numled);
   FastLED.clear();
         }

void loop() {    
   for(uint8_t y=0 ; y<1 ; y++){
     for(uint8_t x=0; x < MatrixWidth; x++){ 
         leds[XY (x, y)].r = redarray[x][y];
         leds[XY (x, y)].g = 0;
         leds[XY (x, y)].b = 0;

         FastLED.show(); 
         delay(50);         
     }
   }   
 }

  uint16_t XY( uint8_t x, uint8_t y)  
  {
      uint16_t i;

      if( MatrixSerpentineLayout == true) {
          if( y & 0x01) {
          // Odd rows run backwards
          uint8_t reverseX = (MatrixWidth - 1) - x;
          i = (y * MatrixWidth) + reverseX;
    } else {
         // Even rows run forwards
         i = (y * MatrixWidth) + x;
    }
}  
   return i;
}

The following is redarray header -

//RED const byte redarray[3][36] PROGMEM = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

};

How to remove this warning. The redarray is not being read properly by arduino. THe above code should make the 36 LEDs turn off (black) as per the header file. They are randomly lit red... I am totally perplexed!

Plz help if somebody can. Thanks!

2

MatrixWidth is 36. redarray[] has 3 elements. The compiler has detected that your code will likely blow up on the 4th go through the loop. Make sure your code is accessing the dimensions correctly.

| improve this answer | |
  • (great name btw! :P) ...I referred to this link tutorialspoint.com/cplusplus/cpp_multi_dimensional_arrays.htm and it says that the brackets around indvidual elements are optional. So, by that , my redarray is a 3 row 36 column array. Which one is correct? Any could you please tell how to access the dimensions correctly. I am stuck on this since quite a long time. the leds[XY(x,y)]= redarray[x][y] ....is this accessing of array and allocating to leds correct???? Thanks! – fattypanda May 11 '16 at 15:29
  • What do you mean which is correct? Your first dimension only has a fixed 3 elements. Attempting to access beyond that is a bug. – Ignacio Vazquez-Abrams May 11 '16 at 15:33
  • I declared my redarray as { {r,r,r,r...36 elements}, {e,e,e,e,e...36 elements}, {t,t,t,t,...36 elements} }; in three rows...isn't that a 3*36 matrix? On the link, it is defined like this only....each row within {} ?? Thats my confusion.... – fattypanda May 11 '16 at 15:49
  • You're too mired in trivialities. Your first dimension has three elements. If you try to access it with a value greater than 2 then your code may blow up. – Ignacio Vazquez-Abrams May 11 '16 at 15:54
  • 2
    You've already defined the 3*36 array. But you're treating it like a 36*3 array. – Ignacio Vazquez-Abrams May 11 '16 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.