0

NeoPixel Help!
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

NeoPixel Help!

by mrwadepro on Mon Nov 13, 2017 7:21 pm

Pretty much I cannot figure out how to get setPixelColor to work correctly with a variable taken from the pixelMap. If I print the returned value from the loop it is correct. If I manually type in a 1, for instance. The pixel lights as expected, however if I keep the code that has the 'i' to the call for the 2D array it just doesn't do anything. And like I said I know it is getting the correct values because I am printing them. I cannot figure this out! Please help!

Issue
Code: Select all | TOGGLE FULL SIZE
     
  for(int i=0;i < 5;i++){
   
    current = pixelMap[i][1];
    strip.setPixelColor(current,0,0,25);
    strip.show();
  }


pixelMap defined here:
Code: Select all | TOGGLE FULL SIZE
int pixelMap[20][25] = {
{25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1},
{26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50},
{75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51},
{76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100},
{125,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101},
{126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150},
{175,174,173,172,171,170,169,168,167,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,151},
{176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200},
{225,224,223,222,221,220,219,218,217,216,215,214,213,212,211,210,209,208,207,206,205,204,203,202,201},
{226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250},
{275,274,273,272,271,270,269,268,267,266,265,264,263,262,261,260,259,258,257,256,255,254,253,252,251},
{276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300},
{325,324,323,322,321,320,319,318,317,316,315,314,313,312,311,310,309,308,307,306,305,304,303,302,301},
{326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350},
{375,374,373,372,371,370,369,368,367,366,365,364,363,362,361,360,359,358,357,356,355,354,353,352,351},
{376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400},
{425,424,423,422,421,420,419,418,417,416,415,414,413,412,411,410,409,408,407,406,405,404,403,402,401},
{426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450},
{475,474,473,472,471,470,469,468,467,466,465,464,463,462,461,460,459,458,457,456,455,454,453,452,451},
{476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500}
};

mrwadepro
 
Posts: 9
Joined: Mon Nov 13, 2017 7:17 pm

Re: NeoPixel Help!

by kcl1s on Mon Nov 13, 2017 11:16 pm

Not sure what you are going for here but the code snipets look OK assuming you declare current as an int. So you say you put a Serial.println(current); in that for loop you get 24, 27, 74, 77, 124? What happens when you replace current in the setPixelColor to one of these values?

Keith

kcl1s
 
Posts: 423
Joined: Tue Aug 30, 2016 12:06 pm

Re: NeoPixel Help!

by mrwadepro on Mon Nov 13, 2017 11:19 pm

It works if I hard code it, but once I put in pixelMap[i][i] it just stops working. I even did
Code: Select all | TOGGLE FULL SIZE
int pixel = pixelMap[i][i];
strip.SetPixelColor(pixel,0,0,255);

Yet it still doesn't like that.

mrwadepro
 
Posts: 9
Joined: Mon Nov 13, 2017 7:17 pm

Re: NeoPixel Help!

by kcl1s on Mon Nov 13, 2017 11:26 pm

What happens if you take the array out of play and just run strandtest. Do all pixels work?

Keith

kcl1s
 
Posts: 423
Joined: Tue Aug 30, 2016 12:06 pm

Re: NeoPixel Help!

by mrwadepro on Tue Nov 14, 2017 12:14 am

Yes, my LEDS work when I do that. If you hard code the pixel index in SetPixelcolor it works.

mrwadepro
 
Posts: 9
Joined: Mon Nov 13, 2017 7:17 pm

Re: NeoPixel Help!

by jim_lee on Tue Nov 14, 2017 2:00 am

Post all your code? There may be something going on effecting where you are focusing that you're not seeing.

-jim lee

jim_lee
 
Posts: 330
Joined: Thu May 24, 2012 8:24 pm

Re: NeoPixel Help!

by chemdoc77 on Tue Nov 14, 2017 10:29 am

Try changing :
Code: Select all | TOGGLE FULL SIZE
int pixelMap[20][25] =
to
Code: Select all | TOGGLE FULL SIZE
int pixelMap[ ][ ] =
Also try changing it to
Code: Select all | TOGGLE FULL SIZE
int pixelMap[21][26] =

you might want to look at:
https://www.arduino.cc/reference/en/language/variables/data-types/array/

and here is a NeoPixel sketch of mine using lots of arrays:

https://github.com/chemdoc77/Adafruit_NeoPixel_Library/blob/master/CD77_NeoPixel_NeoMatrix_8X8_panel_Fun_with_Arduino/CD77_NeoPixel_NeoMatrix_8X8_panel_Fun_with_Arduino.ino

chemdoc77
 
Posts: 86
Joined: Mon Jan 28, 2013 9:32 am

Re: NeoPixel Help!

by mrwadepro on Tue Nov 14, 2017 10:47 am

Here's all of the code.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(525, PIN, NEO_GRB + NEO_KHZ800);
int snakeArray[10];
int snakeSize = 2;
uint16_t pixelMap[20][25] = {
{25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1},
{26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50},
{75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51},
{76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100},
{125,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101},
{126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150},
{175,174,173,172,171,170,169,168,167,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,151},
{176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200},
{225,224,223,222,221,220,219,218,217,216,215,214,213,212,211,210,209,208,207,206,205,204,203,202,201},
{226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250},
{275,274,273,272,271,270,269,268,267,266,265,264,263,262,261,260,259,258,257,256,255,254,253,252,251},
{276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300},
{325,324,323,322,321,320,319,318,317,316,315,314,313,312,311,310,309,308,307,306,305,304,303,302,301},
{326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350},
{375,374,373,372,371,370,369,368,367,366,365,364,363,362,361,360,359,358,357,356,355,354,353,352,351},
{376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400},
{425,424,423,422,421,420,419,418,417,416,415,414,413,412,411,410,409,408,407,406,405,404,403,402,401},
{426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450},
{475,474,473,472,471,470,469,468,467,466,465,464,463,462,461,460,459,458,457,456,455,454,453,452,451},
{476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500}
};
int gameMap[20][25]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

void setup()
{
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code


  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  Serial.begin(9600);
}

void loop()
{
createSnake();

}

void createSnake()
{
  for(int i = 0; i < 10; i++)
  {
    //Doesnt work
    strip.setPixelColor(pixelMap[i][i],0,0,10);
    }
 strip.show();
}


}
Last edited by mrwadepro on Tue Nov 14, 2017 6:31 pm, edited 5 times in total.

mrwadepro
 
Posts: 9
Joined: Mon Nov 13, 2017 7:17 pm

Re: NeoPixel Help!

by kcl1s on Tue Nov 14, 2017 12:32 pm

You are calling that function over and over with no delay. Add a 10ms delay in your loop and see if it helps.

Keith

kcl1s
 
Posts: 423
Joined: Tue Aug 30, 2016 12:06 pm

Re: NeoPixel Help!

by kcl1s on Tue Nov 14, 2017 12:37 pm

And put the strip.show(); outside the for loop so it is only called once per function call

Keith

kcl1s
 
Posts: 423
Joined: Tue Aug 30, 2016 12:06 pm

Re: NeoPixel Help!

by gfvalvo on Tue Nov 14, 2017 1:20 pm

chemdoc77 wrote:Try changing :
Code: Select all | TOGGLE FULL SIZE
int pixelMap[20][25] =
to
Code: Select all | TOGGLE FULL SIZE
int pixelMap[ ][ ] =

I believe only the first array dimension of such an initialization is allowed to be left blank:
Code: Select all | TOGGLE FULL SIZE
int pixelMap[][25] = {
  {25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
  {26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50},
  {75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51}
};

gfvalvo
 
Posts: 217
Joined: Fri Oct 07, 2016 1:35 pm

Re: NeoPixel Help!

by mrwadepro on Tue Nov 14, 2017 3:30 pm

I’ve tried all of these suggestions and it still doesn’t work. It works with a one dimensional array but once the 2D array is used it doesn’t.

By the way I appreciate all the suggestions! Please keep them coming! I’m willing to try anything, it’s really bothering me lol.

mrwadepro
 
Posts: 9
Joined: Mon Nov 13, 2017 7:17 pm

Re: NeoPixel Help!

by gfvalvo on Tue Nov 14, 2017 4:08 pm

This is just wrong:
Code: Select all | TOGGLE FULL SIZE
void createSnake()
{
  for (int i = 0; i < 60; i++)
  {
    //Doesnt work
    strip.setPixelColor(pixelMap[i][i], 0, 0, 10);
    strip.show();
  }
}

* pixelMap is not a 60x60 array. You're accessing memory you don't own.
* Don’t call strip.show() on every iteration.


This is wrong:
Code: Select all | TOGGLE FULL SIZE
void drawSnake(int snake[])
{
  for (int i = 0; i < 10; i++)
  {
    strip.setPixelColor(2, 0, 255, 0);
    strip.show();
  }
}

* You’re setting the same pixel every time through the loop.
* Don’t call strip.show() on every iteration.


This is wrong:
Code: Select all | TOGGLE FULL SIZE
  //Bottom
  for (int p = 477; p <= 499; p++)
  {
    strip.setPixelColor(p, 0, 255, 0);
    strip.show();
  }

* Don’t call strip.show() on every iteration.

gfvalvo
 
Posts: 217
Joined: Fri Oct 07, 2016 1:35 pm

Re: NeoPixel Help!

by mrwadepro on Tue Nov 14, 2017 6:12 pm

I changed my code to reflect the feedback, I didn't mean to put i=60 in the for loop. I did it with 10 before and it gave me the same results.

mrwadepro
 
Posts: 9
Joined: Mon Nov 13, 2017 7:17 pm

Re: NeoPixel Help!

by jim_lee on Tue Nov 14, 2017 6:19 pm

You are also walloping 1/2 your RAM on the two arrays. You may be running out of RAM when everything else is added up.

-jim lee

jim_lee
 
Posts: 330
Joined: Thu May 24, 2012 8:24 pm

Please be positive and constructive with your questions and comments.