question regarding arrarys

I have an arrary that represents a single line in tetris

int lin1[9]={0,0,0,0,0,0,0,0,0};

if I want to change the value of the whole arrary do I have to do the individual lin1[0]=1;lin1[1]=1;lin1[2]=1;lin1[3]=1; // and so on... or is there a way I can set all of them at once?

Do you really need the array to be int?

Could byte suffice to your needs (255 values)

If you were to use bytes and Given the memory is contiguous in the array, you could use memset

If will not be super much faster than doing your for loop though...

Setting them to zero is easy:

memset(lin, 0, sizeof(lin));

However, setting them to 1 is more difficult because memset() is designed to work with char data, which means if you tried to set it using 1, all 18 bytes would be set to 1...not what you want. Can you change the data to byte or char?

I'm setting it as a int so that in the future I can set them to different numbers to make different colors for example 1 might be blue 2 could be red 3 could be green.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 



int lnc=0;
int scal=4;
//the cube...OF DEATH... or tetris
int lin4[9]={1,1,1,1,0,1,1,1,1};
int lin3[9]={1,1,1,1,1,0,1,1,1};
int lin2[9]={1,1,1,1,1,1,0,1,1};
int lin1[9]={1,1,1,1,1,1,1,1,1};


int pos1=0;
void setup() {
  // put your setup code here, to run once:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  display.display();
 Serial.begin(9600);
 }


void loop() {

 // tone(3,200,50);
  display.clearDisplay();
display.setRotation(2);


//attemt to set a entire line to something diffrent...  i also want to read the entire state of the arrary for example if the entire arrary = 1 then set it to all be 0
lin1[9]={1,1,1,0,0,0,1,1,1};
//error





//line 1

for(int x = 0; x < 9; x = x + 1)
  
   {
      if (lin1[x]==1){display.fillRect(45+x*scal,20,scal,scal,WHITE);}

     
    }





//line 2 

for(int y = 0; y < 9; y = y + 1)
  
   {
      if (lin2[y]==1){display.fillRect(45+y*scal,20-scal,scal,scal,WHITE);}

     

    }



//line 3 


    for(int z = 0; z < 9; z = z + 1)
  
   {
      if (lin3[z]==1){display.fillRect(45+z*scal,20-8,scal,scal,WHITE);}

     

            
     

    }




    //line 4


    for(int z1 = 0; z1 < 9; z1 = z1 + 1)
  
   {
      if (lin4[z1]==1){display.fillRect(45+z1*scal,20-12,scal,scal,WHITE);}

     

            
     

    }






display.display();

delay(500);
}

brenden_nerd_: I'm setting it as a int so that in the future I can set them to different numbers to make different colors for example 1 might be blue 2 could be red 3 could be green.

whoosh!

As long as the numbers are less than 255, you can use bytes instead of ints.

You could also make your array into a union and set it with 2 uint_64's.

As said before - a byte gets you 255 possibility - that's already a lot of choices isn't it?

yeah that's perfect I don't know why but I was figuring a byte would only allow for 2 options being 1 and 0... but that's a boline isn't It... I see about it, but afterwards how do I change the ENTIRE arrary into a different number I was thinking about this further and if the line is deleted the line above it has to move down will it be possible to simply make them swap positions?

brenden_nerd_: but that's a boline isn't It...

The word is boolean, but yes.

To swap arrays you could use memcpy.

ok will do! Boolean then ill Remember that.

'Boolean' - named after Henry Boole, who developed what is now called boolean algebra.

As I said, use a union and some 64 bit values.

union data {
      byte data[16];
     uint_64 set[2];
} mystuff;

mystuff.data[0] = 21;

byte get_it = mystuff.data[3];

uint_64 set_high = 0x000000000000000EE;
uint_64 set_low = 0x8877665544332211; 
mystuff.set[1] = set_high;
mystuff.set[0] = set_low;