code writing help 16x16 matrix

Hi gang, first off let me say I am new to the world of ARDUINO and coding. I have been tinkering only for about the last month in my spare time(which has not been a lot). Enough said!

I have made myself a 16x16 matrix (256 pixel) with ws2812 in ZIGZAG configuration, and I am using a ARDUINO UNO to control them.

So what I am trying to figure out is a “Simple or easy” way to alter my state of programing.

I will try to explain the best I can.

first off, I am writing code to illuminate all leds in a rainbow pattern, that lights all leds, and from the center out changes through the color spectrum.

Then I would like to have the next cycle do a totally different pattern. I can accomplish this by changing one of the lines, shown below

example:

strip.setPixelColor(ledArray1*, Wheel((i+j) & 255)); “this is original code line”*
then if I add " *2 or other # up to 256" after ((I+j) I get a different result, so new code is this:
strip.setPixelColor(ledArray1_, Wheel((i+j)2 & 255)); "this is with # added"_
so this is what I am trying to accomplish, and am not sure how to write it, or if it is even possible.
in an easier manner than writing the code over and over(which I could do.
I would like to use multiple #'s for multiple outcomes in a loop cycle.
ARDUINO UNO
16x16 matrix (ws2812 led strips) ZIGZAG configuration - homemade
running ADAFRUIT_NEOPIXEL
hope I have provided enough information
thanks in advance
and go easy on me, I am trying but have a limited amount of time I can commit to world of ARDUINO.
sorry, was not sure how to put code in, so I just put it as an attachment down below. :frowning:
_
```
_
*#include <Adafruit_NeoPixel.h>
#define PIN 4                       
#define NUM_LEDS 256

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

int ledArray1 = //outside into center 16x16 (256 pixels)
{
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,47,48,79,
80,111,112,143,144,175,176,207,208,
239,240,241,242,243,244,245,246,247,248,
249,250,251,252,253,254,255,224,223,192,
191,160,159,128,127,96,95,64,63,32,
31,30,29,28,27,26,25,24,23,22,
21,20,19,18,17,46,49,78,81,110,
113,142,145,174,177,206,209,238,237,236,
235,234,233,232,231,230,229,228,227,226,
225,222,193,190,161,158,129,126,97,94,
65,62,33,34,35,36,37,38,39,40,
41,42,43,44,45,50,77,82,109,114,
141,146,173,178,205,210,211,212,213,214,
215,216,217,218,219,220,221,194,189,162,
157,130,125,98,93,66,61,60,59,58,
57,56,55,54,53,52,51,76,83,108,
115,140,147,172,179,204,203,202,201,200,
199,198,197,196,195,188,163,156,131,124,
99,92,67,68,69,70,71,72,73,74,75,
84,107,116,139,148,171,180,181,182,183,
184,185,186,187,164,155,132,123,100,91,
90,89,88,87,86,85,106,117,138,149,
170,169,168,167,166,165,154,133,122,101,
102,103,104,105,118,137,150,151,152,153,
134,121,120,119,136,135,

};
    void setup()
{
  strip.begin();
  strip.setBrightness(30);
  strip.show();
  }
void loop()
{
  rainbow(10); // rainbow pattern full screen…
  }
//-------------------------rainbow---------------------------------------------------
void rainbow(uint8_t wait)
{
  for (int n=0; n<4; n++)// n<(#) number of times it will cycle pattern
  {
    uint16_t i, j;

for(j=0; j<256; j++)
    {
    for(i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(ledArray1[i], Wheel((i+j) & 255));
    }
    strip.show();
    delay(2);
    }
  }
}
//----------------------------------------------------------------------------------------
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
  WheelPos -= 85;
  return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
  WheelPos -= 170;
  return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  strip.show();
    delay(10);
}
_
```_
_
for arduino fourm (code).txt (2.24 KB)*_

Well since I submitted my ^^ ABOVE^^ question, I have learned a lot. :frowning: :stuck_out_tongue:

I wrote more code, and have drastically improved my knowledge of the the coding(sort of)

#include <Adafruit_NeoPixel.h>
#define PIN 4                         
#define NUM_LEDS 256 

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

int ledArray1[] = //outside into center 16x16 (256 pixels)
{
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,47,48,79,
80,111,112,143,144,175,176,207,208,
239,240,241,242,243,244,245,246,247,248,
249,250,251,252,253,254,255,224,223,192,
191,160,159,128,127,96,95,64,63,32,
31,30,29,28,27,26,25,24,23,22,
21,20,19,18,17,46,49,78,81,110,
113,142,145,174,177,206,209,238,237,236,
235,234,233,232,231,230,229,228,227,226,
225,222,193,190,161,158,129,126,97,94,
65,62,33,34,35,36,37,38,39,40,
41,42,43,44,45,50,77,82,109,114,
141,146,173,178,205,210,211,212,213,214,
215,216,217,218,219,220,221,194,189,162,
157,130,125,98,93,66,61,60,59,58,
57,56,55,54,53,52,51,76,83,108,
115,140,147,172,179,204,203,202,201,200,
199,198,197,196,195,188,163,156,131,124,
99,92,67,68,69,70,71,72,73,74,75,
84,107,116,139,148,171,180,181,182,183,
184,185,186,187,164,155,132,123,100,91,
90,89,88,87,86,85,106,117,138,149,
170,169,168,167,166,165,154,133,122,101,
102,103,104,105,118,137,150,151,152,153,
134,121,120,119,136,135,                                 

  };
     void setup() 
{
  strip.begin();
  strip.setBrightness(30);
  strip.show();
  }
void loop()
{
  rainbow6(10);// rainbow pattern full screen...
  rainbow2(10);
  rainbow3(10);
  rainbow4(10);
  rainbow5(10);
  rainbow(10);
  }
//-------------------------rainbow---------------------------------------------------
void rainbow(uint8_t wait) 
{
  for (int n=0; n<1; n++)// n<(#) number of times it will cycle pattern
  {
    uint16_t i, j;

     for(j=0; j<256; j++) 
     {
    for(i=0; i<strip.numPixels(); i++) 
     {
      strip.setPixelColor(ledArray1[i], Wheel((i+j) & 255));
     }
    strip.show();
    delay(2);
     }
  }
}
//----------------------------------------------------------------------------------------
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  strip.show();
    delay(10);
}

//-------------------------rainbow2---------------------------------------------------
void rainbow2(uint8_t wait) 
{
  for (int n=0; n<1; n++)// n<(#) number of times it will cycle pattern
  {
    uint16_t i, j;

     for(j=0; j<256; j++) 
     {
    for(i=0; i<strip.numPixels(); i++) 
     {
      strip.setPixelColor(ledArray1[i], Wheel2((i+j)*4 & 255));
     }
    strip.show();
    delay(2);
     }
  }
}
//----------------------------------------------------------------------------------------
uint32_t Wheel2(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  strip.show();
    delay(10);
}
//-------------------------rainbow3---------------------------------------------------
void rainbow3(uint8_t wait) 
{
  for (int n=0; n<1; n++)// n<(#) number of times it will cycle pattern
  {
    uint16_t i, j;

     for(j=0; j<256; j++) 
     {
    for(i=0; i<strip.numPixels(); i++) 
     {
      strip.setPixelColor(ledArray1[i], Wheel3((i+j)*8 & 255));
     }
    strip.show();
    delay(2);
     }
  }
}
//----------------------------------------------------------------------------------------
uint32_t Wheel3(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  strip.show();
    delay(10);
}
//-------------------------rainbow4---------------------------------------------------
void rainbow4(uint8_t wait) 
{
  for (int n=0; n<1; n++)// n<(#) number of times it will cycle pattern
  {
    uint16_t i, j;

     for(j=0; j<256; j++) 
     {
    for(i=0; i<strip.numPixels(); i++) 
     {
      strip.setPixelColor(ledArray1[i], Wheel4((i+j)*16 & 255));
     }
    strip.show();
    delay(2);
     }
  }
}
//----------------------------------------------------------------------------------------
uint32_t Wheel4(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  strip.show();
    delay(10);
}
//-------------------------rainbow5---------------------------------------------------
void rainbow5(uint8_t wait) 
{
  for (int n=0; n<1; n++)// n<(#) number of times it will cycle pattern
  {
    uint16_t i, j;

     for(j=0; j<256; j++) 
     {
    for(i=0; i<strip.numPixels(); i++) 
     {
      strip.setPixelColor(ledArray1[i], Wheel5((i+j)*32 & 255));// I like this effect
     }
    strip.show();
    delay(75);
     }
  }
}
//----------------------------------------------------------------------------------------
uint32_t Wheel5(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  strip.show();
    delay(10);
}
//-------------------------rainbow6---------------------------------------------------
void rainbow6(uint8_t wait) 
{
  for (int n=0; n<1; n++)// n<(#) number of times it will cycle pattern
  {
    uint16_t i, j;

     for(j=0; j<256; j++) 
     {
    for(i=0; i<strip.numPixels(); i++) 
     {
      strip.setPixelColor(ledArray1[i], Wheel6((i+j)*64 & 255));
     }
    strip.show();
    delay(50);
     }
  }
}
//----------------------------------------------------------------------------------------
uint32_t Wheel6(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  strip.show();
    delay(10);
}

this would be the best way I could explain what I trying to achieve, wanting to learn an easier way to write the code.

I also discovered that when I change the delay time in the “rainbow#” line/loop that I get different results/effects.

also learnt how to re-arrange their order, so the Loop" I am working with is the first to be displayed. :slight_smile:

I am off to seek more knowledge.

I am a 49 year old, and still learning new things everyday! :wink: