Sampling color data for LED matrix

Hello,

I’m working with a custom made 16*16 white led matrix connected to an arduino. I’ve written a sketch that samples 256 pixels using the ‘get()’ function, converts the data, and sends to the arduino over osc. It works but is extremely slow. Note the code below is just for 16 leds.

I understand that the loadPixels function is probably more suitable for this, but I’m struggling to understand how to grab specific pixels from it.

Also, how might I go about writing a loop to convert all of the color data, instead of rewriting the same 4 lines of code.

Thanks

import oscP5.*;
import processing.serial.*;
 
Serial serial;
OscSerial osc;
String serialName = "/dev/tty.usbmodem40915201";

int led[];

int y1 = 15;
int y2 = 45;
int y3 = 75;
int y4 = 105;
int y5 = 135;
int y6 = 165;
int y7 = 195;
int y8 = 225;
int y9 = 255;
int y10 = 285;
int y11 = 315;
int y12 = 345;
int y13 = 375;
int y14 = 405;
int y15 = 435;
int y16 = 465;

int x1 = 15;
int x2 = 45;
int x3 = 75;
int x4 = 105;
int x5 = 135;
int x6 = 165;
int x7 = 195;
int x8 = 225;
int x9 = 255;
int x10 = 285;
int x11 = 315;
int x12 = 345;
int x13 = 375;
int x14 = 405;
int x15 = 435;
int x16 = 465;



// 2d arrays to hold current and next generations
int[][] current, next;
// prob of life, 0 < p < 1
float p;
// pause toggle
boolean pause;
// block and border vars: bx cell width in pixels, by cell height in
// pixels, bw border width in pixels
int bx, by, bw;
// grid size: dimensions of the 2d cell arrays
int gn, gm;

void setup() {
  serial = new Serial(this, serialName, 9600);
  osc = new OscSerial(this, serial);
  osc.plug(this, "myFunction", "/helloFromArduino");
  
  size(500, 500);
  frameRate(10); 
  bx = 30;
  by = 30;
  bw = 1;
  gn = 16;
  gm = 16;
  current = new int[gn][gm];
  next = new int[gn][gm];
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      current[i][j] = 0;
      next[i][j] = 0;
    }
    

  }
  
  // life prob
  p=0.2;
  RandomCells(p);
  pause = false;
}

void draw() {
  background(0);
  DrawCells();
  if (!pause) ConwayStep();
  
  int c0 = get(x1, y1);                   //get color data from x y point
  float p0 = brightness(c0);               //converts random color data to 0-2555
  float f0 = map(p0,0,255,0,703);      // converts rgb value to 703 led value
  int led0 = int(f0);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/0");
  msg.add(led0);
  osc.send(msg);
  }

    int c1 = get(x2, y1);                   //get color data from x y point
  float p1 = brightness(c1);               //converts random color data to 0-2555
  float f1 = map(p1,0,255,0,703);      // converts rgb value to 703 led value
  int led1 = int(f1);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/1");
  msg.add(led1);
  osc.send(msg);
  }
  
  int c2 = get(x3, y1);                   //get color data from x y point
  float p2 = brightness(c2);               //converts random color data to 0-2555
  float f2 = map(p2,0,255,0,703);      // converts rgb value to 703 led value
  int led2 = int(f2);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/2");
  msg.add(led2);
  osc.send(msg);
  }
  
   int c3 = get(x4, y1);                   //get color data from x y point
  float p3 = brightness(c3);               //converts random color data to 0-2555
  float f3 = map(p3,0,255,0,703);      // converts rgb value to 703 led value
  int led3 = int(f3);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/3");
  msg.add(led3);
  osc.send(msg);
  }
  
   int c4 = get(x5, y1);                   //get color data from x y point
  float p4 = brightness(c4);               //converts random color data to 0-2555
  float f4 = map(p4,0,255,0,703);      // converts rgb value to 703 led value
  int led4 = int(f4);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/4");
  msg.add(led4);
  osc.send(msg);
  }
  
   int c5 = get(x6, y1);                   //get color data from x y point
  float p5 = brightness(c5);               //converts random color data to 0-2555
  float f5 = map(p5,0,255,0,703);      // converts rgb value to 703 led value
  int led5 = int(f5);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/5");
  msg.add(led5);
  osc.send(msg);
  }
  
   int c6 = get(x7, y1);                   //get color data from x y point
  float p6 = brightness(c6);               //converts random color data to 0-2555
  float f6 = map(p6,0,255,0,703);      // converts rgb value to 703 led value
  int led6 = int(f6);                  //converts float to int
 // int led6 = 703;
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/6");
  msg.add(led6);
  osc.send(msg);
  }
  
   int c7 = get(x8, y1);                   //get color data from x y point
  float p7 = brightness(c7);               //converts random color data to 0-2555
  float f7 = map(p7,0,255,0,703);      // converts rgb value to 703 led value
  int led7= int(f7);                  //converts float to int
  
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/7");
  msg.add(led7);
  osc.send(msg);
  }
  
   int c8 = get(x9, y1);                   //get color data from x y point
  float p8 = brightness(c8);               //converts random color data to 0-2555
  float f8 = map(p8,0,255,0,703);      // converts rgb value to 703 led value
  int led8 = int(f8);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/8");
  msg.add(led8);
  osc.send(msg);
  }
  
   int c9 = get(x10, y1);                   //get color data from x y point
  float p9 = brightness(c9);               //converts random color data to 0-2555
  float f9 = map(p9,0,255,0,703);      // converts rgb value to 703 led value
  int led9 = int(f9);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/9");
  msg.add(led9);
  osc.send(msg);
  }
  
   int c10 = get(x11, y1);                   //get color data from x y point
  float p10 = brightness(c10);               //converts random color data to 0-2555
  float f10 = map(p10,0,255,0,703);      // converts rgb value to 703 led value
  int led10 = int(f10);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/0");
  msg.add(led10);
  osc.send(msg);
  }
  
   int c11 = get(x12, y1);                   //get color data from x y point
  float p11 = brightness(c11);               //converts random color data to 0-2555
  float f11 = map(p11,0,255,0,703);      // converts rgb value to 703 led value
  int led11 = int(f11);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/1");
  msg.add(led11);
  osc.send(msg);
  }
  
   int c12 = get(x13, y1);                   //get color data from x y point
  float p12 = brightness(c12);               //converts random color data to 0-2555
  float f12 = map(p12,0,255,0,703);      // converts rgb value to 703 led value
  int led12 = int(f12);                  //converts float to int
 
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/2");
  msg.add(led12);
  osc.send(msg);
  }
  
   int c13 = get(x14, y1);                   //get color data from x y point
  float p13 = brightness(c13);               //converts random color data to 0-2555
  float f13 = map(p13,0,255,0,703);      // converts rgb value to 703 led value
  int led13 = int(f13);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/3");
  msg.add(led13);
  osc.send(msg);
  }
  
   int c14 = get(x15, y1);                   //get color data from x y point
  float p14 = brightness(c14);               //converts random color data to 0-2555
  float f14 = map(p14,0,255,0,703);      // converts rgb value to 703 led value
  int led14 = int(f14);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/4");
  msg.add(led14);
  osc.send(msg);
  }
  
     int c15 = get(x16, y1);                   //get color data from x y point
  float p15 = brightness(c15);               //converts random color data to 0-2555
  float f15 = map(p15,0,255,0,703);      // converts rgb value to 703 led value
  int led15 = int(f15);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/5");
  msg.add(led15);
  osc.send(msg);
  }
  

}


void keyPressed() {

  if (key=='c') {
    for (int i=0;i<gn;i++) {
      for (int j=0;j<gm;j++) {
        current[i][j] = 0;
      }
    }
  }
  if (key=='p' || key==' ') {
    pause = !pause;
  }
  if (key=='q') {
    exit();
  }
  if (key=='r') {
    RandomCells(p);
  }
}

void mouseDragged() {
  // block size
  int blockSize = 2; 
  for (int i=int(mouseX/(bx+bw)-blockSize); i<=int(mouseX/(bx+bw)+blockSize); i++) {
    for (int j=int(mouseY/(by+bw)-blockSize); j<=int(mouseY/(by+bw)+blockSize); j++) {
      if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
    }
  }
}

void mouseClicked() {
  // block size
  int i=int(mouseX/(bx+bw));
  int j=int(mouseY/(by+bw));
  if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
}
void RandomCells(float p) {
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      if (random(1)<p) {
        current[i][j] = 1;
      }
    }
  }
}

void DrawCells() {
  noStroke();
  fill(255);
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      if (current[i][j]==1) {
        rect(i*(bx+bw), j*(by+bw), bx, by);
      }
    }
  }
}

void ConwayStep() {

  int nbhdSum;

  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      nbhdSum=NeighborhoodSum(i, j);
      if (nbhdSum<2 || nbhdSum>3) next[i][j]=0;
      if (nbhdSum==3) next[i][j] = 1;
      if (nbhdSum==2) next[i][j] = current[i][j];
    }
  }
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      current[i][j] = next[i][j];
    }
  }
}

// compute the neighborhood sum with bounds checking
int NeighborhoodSum(int i, int j) {
  int sum = 0;
  int k, l;
  for (k=i-1;k<=i+1;k++) {
    for (l=j-1;l<=j+1;l++) {
      if (k>=0 && k<gn && l>=0 && l<gm && !(k==i && l==j)) {
        sum+=current[k][l];
      }
    }
  }
  return sum;
 
}

hi, some great code you got there, where you got the examples from,

i think main problem is you need practice

  • array
  • for loop
  • make functions

but your question about
get(x,y);
and possibly speed is a big one,
lucky you in this case not need it at all.
the info what ?cell? is on/off, white/black
is already available to you via the 1/0 from the current array.
so only use that information
inside your new function
void sendosc(x,y)

Hi,

Thanks for the reply. Im just using this conway sketch as an example for now, so i would like to be able to sample the actual color data from the sketch.

I noticed if i separate all of the osc related code out of ‘void draw’ and into its own function the sketch runs quickly however the osc doesnt work. Any ideas on why that might be? Would ‘get()’ or anything else need to be in the the draw function to work properly for any reason?

import oscP5.*;
import processing.serial.*;
 
Serial serial;
OscSerial osc;
String serialName = "/dev/tty.usbmodem40915201";

int led[];

int y1 = 15;
int y2 = 45;
int y3 = 75;
int y4 = 105;
int y5 = 135;
int y6 = 165;
int y7 = 195;
int y8 = 225;
int y9 = 255;
int y10 = 285;
int y11 = 315;
int y12 = 345;
int y13 = 375;
int y14 = 405;
int y15 = 435;
int y16 = 465;

int x1 = 15;
int x2 = 45;
int x3 = 75;
int x4 = 105;
int x5 = 135;
int x6 = 165;
int x7 = 195;
int x8 = 225;
int x9 = 255;
int x10 = 285;
int x11 = 315;
int x12 = 345;
int x13 = 375;
int x14 = 405;
int x15 = 435;
int x16 = 465;



// 2d arrays to hold current and next generations
int[][] current, next;
// prob of life, 0 < p < 1
float p;
// pause toggle
boolean pause;
// block and border vars: bx cell width in pixels, by cell height in
// pixels, bw border width in pixels
int bx, by, bw;
// grid size: dimensions of the 2d cell arrays
int gn, gm;

void setup() {
  serial = new Serial(this, serialName, 9600);
  osc = new OscSerial(this, serial);
  osc.plug(this, "myFunction", "/helloFromArduino");
  
  size(500, 500);
  frameRate(10); 
  bx = 30;
  by = 30;
  bw = 1;
  gn = 16;
  gm = 16;
  current = new int[gn][gm];
  next = new int[gn][gm];
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      current[i][j] = 0;
      next[i][j] = 0;
    }
    

  }
  
  // life prob
  p=0.2;
  RandomCells(p);
  pause = false;
}

void draw() {
  background(0);
  DrawCells();
  if (!pause) ConwayStep();
}

void osc() {
   
  
  int c0 = get(x1, y1);                   //get color data from x y point
  float p0 = brightness(c0);               //converts random color data to 0-2555
  float f0 = map(p0,0,255,0,703);      // converts rgb value to 703 led value
  int led0 = int(f0);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/0");
  msg.add(led0);
  osc.send(msg);
  }

    int c1 = get(x2, y1);                   //get color data from x y point
  float p1 = brightness(c1);               //converts random color data to 0-2555
  float f1 = map(p1,0,255,0,703);      // converts rgb value to 703 led value
  int led1 = int(f1);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/1");
  msg.add(led1);
  osc.send(msg);
  }

  
  int c2 = get(x3, y1);                   //get color data from x y point
  float p2 = brightness(c2);               //converts random color data to 0-2555
  float f2 = map(p2,0,255,0,703);      // converts rgb value to 703 led value
  int led2 = int(f2);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/2");
  msg.add(led2);
  osc.send(msg);
  }
  
   int c3 = get(x4, y1);                   //get color data from x y point
  float p3 = brightness(c3);               //converts random color data to 0-2555
  float f3 = map(p3,0,255,0,703);      // converts rgb value to 703 led value
  int led3 = int(f3);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/3");
  msg.add(led3);
  osc.send(msg);
  }
  
   int c4 = get(x5, y1);                   //get color data from x y point
  float p4 = brightness(c4);               //converts random color data to 0-2555
  float f4 = map(p4,0,255,0,703);      // converts rgb value to 703 led value
  int led4 = int(f4);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/4");
  msg.add(led4);
  osc.send(msg);
  }
  
   int c5 = get(x6, y1);                   //get color data from x y point
  float p5 = brightness(c5);               //converts random color data to 0-2555
  float f5 = map(p5,0,255,0,703);      // converts rgb value to 703 led value
  int led5 = int(f5);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/5");
  msg.add(led5);
  osc.send(msg);
  }
  
   int c6 = get(x7, y1);                   //get color data from x y point
  float p6 = brightness(c6);               //converts random color data to 0-2555
  float f6 = map(p6,0,255,0,703);      // converts rgb value to 703 led value
  int led6 = int(f6);                  //converts float to int
 // int led6 = 703;
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/6");
  msg.add(led6);
  osc.send(msg);
  }
  
   int c7 = get(x8, y1);                   //get color data from x y point
  float p7 = brightness(c7);               //converts random color data to 0-2555
  float f7 = map(p7,0,255,0,703);      // converts rgb value to 703 led value
  int led7= int(f7);                  //converts float to int
  
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/7");
  msg.add(led7);
  osc.send(msg);
  }
  
   int c8 = get(x9, y1);                   //get color data from x y point
  float p8 = brightness(c8);               //converts random color data to 0-2555
  float f8 = map(p8,0,255,0,703);      // converts rgb value to 703 led value
  int led8 = int(f8);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/8");
  msg.add(led8);
  osc.send(msg);
  }
  
   int c9 = get(x10, y1);                   //get color data from x y point
  float p9 = brightness(c9);               //converts random color data to 0-2555
  float f9 = map(p9,0,255,0,703);      // converts rgb value to 703 led value
  int led9 = int(f9);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/9");
  msg.add(led9);
  osc.send(msg);
  }
  
   int c10 = get(x11, y1);                   //get color data from x y point
  float p10 = brightness(c10);               //converts random color data to 0-2555
  float f10 = map(p10,0,255,0,703);      // converts rgb value to 703 led value
  int led10 = int(f10);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/0");
  msg.add(led10);
  osc.send(msg);
  }
  
   int c11 = get(x12, y1);                   //get color data from x y point
  float p11 = brightness(c11);               //converts random color data to 0-2555
  float f11 = map(p11,0,255,0,703);      // converts rgb value to 703 led value
  int led11 = int(f11);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/1");
  msg.add(led11);
  osc.send(msg);
  }
  
   int c12 = get(x13, y1);                   //get color data from x y point
  float p12 = brightness(c12);               //converts random color data to 0-2555
  float f12 = map(p12,0,255,0,703);      // converts rgb value to 703 led value
  int led12 = int(f12);                  //converts float to int
 
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/2");
  msg.add(led12);
  osc.send(msg);
  }
  
   int c13 = get(x14, y1);                   //get color data from x y point
  float p13 = brightness(c13);               //converts random color data to 0-2555
  float f13 = map(p13,0,255,0,703);      // converts rgb value to 703 led value
  int led13 = int(f13);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/3");
  msg.add(led13);
  osc.send(msg);
  }
  
   int c14 = get(x15, y1);                   //get color data from x y point
  float p14 = brightness(c14);               //converts random color data to 0-2555
  float f14 = map(p14,0,255,0,703);      // converts rgb value to 703 led value
  int led14 = int(f14);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/4");
  msg.add(led14);
  osc.send(msg);
  }
  
  int c15 = get(x16, y1);                   //get color data from x y point
  float p15 = brightness(c15);               //converts random color data to 0-2555
  float f15 = map(p15,0,255,0,703);      // converts rgb value to 703 led value
  int led15 = int(f15);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led2/5");
  msg.add(led15);
  osc.send(msg);
  }
  
 ////////////////////////////////////////////////////////////
 ///ROW 2
 ////////////////////////////////////////////////////////////
 
  int c16 = get(15, 75);                   //get color data from x y point
  float p16 = brightness(c16);               //converts random color data to 0-2555
  float f16 = map(p16,0,255,0,703);      // converts rgb value to 703 led value
  int led16 = int(f16);                  //converts float to int
  
  if (led3 < 5000){
  OscMessage msg = new OscMessage("/led3/0");
  msg.add(led16);
  osc.send(msg);
  }

  int c17 = get(45, 45);                   //get color data from x y point
  float p17 = brightness(c17);               //converts random color data to 0-2555
  float f17 = map(p17,0,255,0,703);      // converts rgb value to 703 led value
  int led17 = int(f17);                  //converts float to int
  
  if (led17 < 5000){
  OscMessage msg = new OscMessage("/led3/1");
  msg.add(led17);
  osc.send(msg);
  }
  
  int c18 = get(75, 45);                   //get color data from x y point
  float p18 = brightness(c18);               //converts random color data to 0-2555
  float f18 = map(p18,0,255,0,703);      // converts rgb value to 703 led value
  int led18 = int(f18);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/2");
  msg.add(led18);
  osc.send(msg);
  }
  
   int c19 = get(105, 45);                   //get color data from x y point
  float p19 = brightness(c19);               //converts random color data to 0-2555
  float f19 = map(p19,0,255,0,703);      // converts rgb value to 703 led value
  int led19 = int(f19);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/3");
  msg.add(led19);
  osc.send(msg);
  }
  
   int c20 = get(135, 45);                   //get color data from x y point
  float p20 = brightness(c20);               //converts random color data to 0-2555
  float f20 = map(p20,0,255,0,703);      // converts rgb value to 703 led value
  int led20 = int(f20);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/4");
  msg.add(led20);
  osc.send(msg);
  }
  
   int c21 = get(165, 45);                   //get color data from x y point
  float p21 = brightness(c21);               //converts random color data to 0-2555
  float f21 = map(p21,0,255,0,703);      // converts rgb value to 703 led value
  int led21 = int(f21);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/5");
  msg.add(led21);
  osc.send(msg);
  }
  
   int c22 = get(195, 45);                   //get color data from x y point
  float p22 = brightness(c22);               //converts random color data to 0-2555
  float f22 = map(p22,0,255,0,703);      // converts rgb value to 703 led value
  int led22 = int(f22);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/6");
  msg.add(led22);
  osc.send(msg);
  }
  
   int c23 = get(225, 45);                   //get color data from x y point
  float p23 = brightness(c23);               //converts random color data to 0-2555
  float f23 = map(p23,0,255,0,703);      // converts rgb value to 703 led value
  int led23= int(f23);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/7");
  msg.add(led23);
  osc.send(msg);
  }
  
   int c24 = get(255, 45);                   //get color data from x y point
  float p24 = brightness(c24);               //converts random color data to 0-2555
  float f24 = map(p24,0,255,0,703);      // converts rgb value to 703 led value
  int led24 = int(f24);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/8");
  msg.add(led24);
  osc.send(msg);
  }
  
   int c25 = get(285, 45);                   //get color data from x y point
  float p25 = brightness(c25);               //converts random color data to 0-2555
  float f25 = map(p25,0,255,0,703);      // converts rgb value to 703 led value
  int led25 = int(f25);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led3/9");
  msg.add(led25);
  osc.send(msg);
  }
  
   int c26 = get(315, 45);                   //get color data from x y point
  float p26 = brightness(c26);               //converts random color data to 0-2555
  float f26 = map(p26,0,255,0,703);      // converts rgb value to 703 led value
  int led26 = int(f26);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led4/0");
  msg.add(led26);
  osc.send(msg);
  }
  
   int c27 = get(345, 45);                   //get color data from x y point
  float p27 = brightness(c27);               //converts random color data to 0-2555
  float f27 = map(p27,0,255,0,703);      // converts rgb value to 703 led value
  int led27 = int(f27);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led4/1");
  msg.add(led27);
  osc.send(msg);
  }
  
   int c28 = get(375, 45);                   //get color data from x y point
  float p28 = brightness(c28);               //converts random color data to 0-2555
  float f28 = map(p28,0,255,0,703);      // converts rgb value to 703 led value
  int led28 = int(f28);                  //converts float to int
 
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led4/2");
  msg.add(led28);
  osc.send(msg);
  }
  
   int c29 = get(405, 45);                   //get color data from x y point
  float p29 = brightness(c29);               //converts random color data to 0-2555
  float f29 = map(p29,0,255,0,703);      // converts rgb value to 703 led value
  int led29 = int(f29);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led4/3");
  msg.add(led29);
  osc.send(msg);
  }
  
   int c30 = get(435, 45);                   //get color data from x y point
  float p30 = brightness(c30);               //converts random color data to 0-2555
  float f30 = map(p30,0,255,0,703);      // converts rgb value to 703 led value
  int led30 = int(f30);                  //converts float to int
 
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led4/4");
  msg.add(led30);
  osc.send(msg);
  }
  
  int c31 = get(465, 45);                   //get color data from x y point
  float p31 = brightness(c31);               //converts random color data to 0-2555
  float f31 = map(p31,0,255,0,703);      // converts rgb value to 703 led value
  int led31 = int(f31);                  //converts float to int

  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led4/5");
  msg.add(led31);
  osc.send(msg);
  }
///////////////////////////////////////////////////////////////////////////////////////////////////
//Row 3
////////////////////////////////////////////////////////////////////////////////////////////////////
 
  int c32 = get(15, y3);                   //get color data from x y point
  float p32 = brightness(c32);               //converts random color data to 0-2555
  float f32 = map(p32,0,255,0,703);      // converts rgb value to 703 led value
  int led32 = int(f32);                  //converts float to int
  
  if (led3 < 5000){
  OscMessage msg = new OscMessage("/led5/0");
  msg.add(led32);
  osc.send(msg);
  }

  int c33 = get(45, y3);                   //get color data from x y point
  float p33 = brightness(c33);               //converts random color data to 0-2555
  float f33 = map(p33,0,255,0,703);      // converts rgb value to 703 led value
  int led33 = int(f33);                  //converts float to int
  
  if (led17 < 5000){
  OscMessage msg = new OscMessage("/led5/1");
  msg.add(led33);
  osc.send(msg);
  }
  
  int c34 = get(75, y3);                   //get color data from x y point
  float p34 = brightness(c34);               //converts random color data to 0-2555
  float f34 = map(p34,0,255,0,703);      // converts rgb value to 703 led value
  int led34 = int(f34);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/2");
  msg.add(led34);
  osc.send(msg);
  }
  
   int c35 = get(105, y3);                   //get color data from x y point
  float p35 = brightness(c35);               //converts random color data to 0-2555
  float f35 = map(p35,0,255,0,703);      // converts rgb value to 703 led value
  int led35 = int(f35);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/3");
  msg.add(led35);
  osc.send(msg);
  }
  
   int c36 = get(135, y3);                   //get color data from x y point
  float p36 = brightness(c36);               //converts random color data to 0-2555
  float f36 = map(p36,0,255,0,703);      // converts rgb value to 703 led value
  int led36 = int(f36);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/4");
  msg.add(led36);
  osc.send(msg);
  }
  
   int c37 = get(165, y3);                   //get color data from x y point
  float p37 = brightness(c37);               //converts random color data to 0-2555
  float f37 = map(p37,0,255,0,703);      // converts rgb value to 703 led value
  int led37 = int(f37);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/5");
  msg.add(led37);
  osc.send(msg);
  }
  
   int c38 = get(195, y3);                   //get color data from x y point
  float p38 = brightness(c38);               //converts random color data to 0-2555
  float f38 = map(p38,0,255,0,703);      // converts rgb value to 703 led value
  int led38 = int(f38);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/6");
  msg.add(led38);
  osc.send(msg);
  }
  
   int c39 = get(225, y3);                   //get color data from x y point
  float p39 = brightness(c39);               //converts random color data to 0-2555
  float f39 = map(p39,0,255,0,703);      // converts rgb value to 703 led value
  int led39= int(f39);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/7");
  msg.add(led39);
  osc.send(msg);
  }
  
   int c40 = get(255, y3);                   //get color data from x y point
  float p40 = brightness(c40);               //converts random color data to 0-2555
  float f40 = map(p40,0,255,0,703);      // converts rgb value to 703 led value
  int led40 = int(f40);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/8");
  msg.add(led40);
  osc.send(msg);
  }
  
   int c41 = get(285, y3);                   //get color data from x y point
  float p41= brightness(c41);               //converts random color data to 0-2555
  float f41 = map(p41,0,255,0,703);      // converts rgb value to 703 led value
  int led41 = int(f41);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led5/9");
  msg.add(led41);
  osc.send(msg);
  }
  

}

////////////////////////////////////////////////////////////////////////////////////


void keyPressed() {

  if (key=='c') {
    for (int i=0;i<gn;i++) {
      for (int j=0;j<gm;j++) {
        current[i][j] = 0;
      }
    }
  }
  if (key=='p' || key==' ') {
    pause = !pause;
  }
  if (key=='q') {
    exit();
  }
  if (key=='r') {
    RandomCells(p);
  }
}

void mouseDragged() {
  // block size
  int blockSize = 2; 
  for (int i=int(mouseX/(bx+bw)-blockSize); i<=int(mouseX/(bx+bw)+blockSize); i++) {
    for (int j=int(mouseY/(by+bw)-blockSize); j<=int(mouseY/(by+bw)+blockSize); j++) {
      if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
    }
  }
}

void mouseClicked() {
  // block size
  int i=int(mouseX/(bx+bw));
  int j=int(mouseY/(by+bw));
  if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
}
void RandomCells(float p) {
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      if (random(1)<p) {
        current[i][j] = 1;
      }
    }
  }
}

void DrawCells() {
  noStroke();
  fill(255);
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      if (current[i][j]==1) {
        rect(i*(bx+bw), j*(by+bw), bx, by);
      }
    }
  }
}

void ConwayStep() {

  int nbhdSum;

  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      nbhdSum=NeighborhoodSum(i, j);
      if (nbhdSum<2 || nbhdSum>3) next[i][j]=0;
      if (nbhdSum==3) next[i][j] = 1;
      if (nbhdSum==2) next[i][j] = current[i][j];
    }
  }
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      current[i][j] = next[i][j];
    }
  }
}
 



// compute the neighborhood sum with bounds checking
int NeighborhoodSum(int i, int j) {
  int sum = 0;
  int k, l;
  for (k=i-1;k<=i+1;k++) {
    for (l=j-1;l<=j+1;l++) {
      if (k>=0 && k<gn && l>=0 && l<gm && !(k==i && l==j)) {
        sum+=current[k][l];
      }
    }
  }
  return sum;
 
}

so if you say the existing graphic show code is just a example,
it does not matter, if you later make a other show still same point,
if you draw a white area on a black background using a array, that array knows
what is white and what is black, so a

get(x,y)

would not be needed.

but sorry, that was not the main question,
you need to write a function instead of
doing:

  int c0 = get(x1, y1);                   //get color data from x y point
  float p0 = brightness(c0);               //converts random color data to 0-2555
  float f0 = map(p0,0,255,0,703);      // converts rgb value to 703 led value
  int led0 = int(f0);                  //converts float to int
  
  if (led0 < 5000){
  OscMessage msg = new OscMessage("/led/0");
  msg.add(led0);
  osc.send(msg);
  }

16 * 16 times.

now you not need to write that code 16 * 16
but still need to call it 16 * 16 times.
for that would need to do FOR loops
example:


void sendosc(int x, int y, String msg0) {
  color c = get(x, y);                   //get color data from x y point
  float p = brightness(c);               //converts random color data to 0-255
  float f = map(p, 0, 255, 0, 703);      // converts rgb value to 703 led value
  int led = int(f);                      //converts float to int

  if (led < 5000) {
    OscMessage msg = new OscMessage(msg0);
    msg.add(led);
    osc.send(msg);
    println(" x "+x+" y "+y+" led "+led+" msg0 "+msg0);
  }
}

void loop16_16() {
  for ( int i = 0; i<16; i++) {
    for ( int k = 0; k<16; k++) {
      int x = 15 + k * 30;
      int y = 15 + i * 30;
      String msg0 = "/led";
      // here need some logic for translate the 16 * 16 to your "/ledA/B" what seems to be decimal??
      // sorry i think that is a mistake in thinking or in arduino code
      // anyhow can generate a string by
      int ledab = i * 16 + k;
      int lA = floor(ledab/10);
      int lB = ledab%10;
      msg0 += lA + "/" + lB;
      sendosc(x, y, msg0);
    }
  }
}

void setup() {
  loop16_16();
}

void draw() {
}

Thanks a lot! I got the for loop to work for the get() function.

The one problem I’m encountering is that in arduino to address an led i need to send a single number ie.‘Tlc.set(led#,brightness);’ instead of an x,y coordinate.

How would you recommend I go about generating a single led number(0,1,2,3,4) to send along with the brightness?

I also switched to regular serial instead of osc.

Thanks

//
int[][] current, next;
// prob of life, 0 < p < 1
float p;
// pause toggle
boolean pause;
// block and border vars: bx cell width in pixels, by cell height in
// pixels, bw border width in pixels
int bx, by, bw;
// grid size: dimensions of the 2d cell arrays
int gn, gm;
//

int led0;
int x;
int y;


int y1 = 15;
int y2 = 45;
int y3 = 75;
int y4 = 105;
int y5 = 135;
int y6 = 165;
int y7 = 195;
int y8 = 225;
int y9 = 255;
int y10 = 285;
int y11 = 315;
int y12 = 345;
int y13 = 375;
int y14 = 405;
int y15 = 435;
int y16 = 465;

int x1 = 15;
int x2 = 45;
int x3 = 75;
int x4 = 105;
int x5 = 135;
int x6 = 165;
int x7 = 195;
int x8 = 225;
int x9 = 255;
int x10 = 285;
int x11 = 315;
int x12 = 345;
int x13 = 375;
int x14 = 405;
int x15 = 435;
int x16 = 465;

String outString;

import processing.serial.*;

Serial myPort;  // Create object from Serial class
String serialName = "/dev/tty.usbmodem40915201";

void setup() {
  size(500,500); //make our canvas 200 x 200 pixels big
  frameRate(10); 
  
  myPort = new Serial(this, serialName, 9600);
  
  //
    bx = 30;
  by = 30;
  bw = 1;
  gn = 16;
  gm = 16;
  current = new int[gn][gm];
  next = new int[gn][gm];
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      current[i][j] = 0;
      next[i][j] = 0;
    }
    

  }
  
  // life prob
  p=0.2;
  RandomCells(p);
  pause = false;
}

void draw() {
  
   background(0);
  DrawCells();
   osc();
  if (!pause) ConwayStep();
}

void osc() {
  
    for (int i = 0; i < 16; i++){
    for (int k = 0; k < 16; k++){
      int x = 15 + i * 30;
      int y = 15 + k * 30;
      int c = get(x,y);
      
      float brightness1 =brightness(c);
      float f0 = map(brightness1,0,255,0,4095);      // converts rgb value to 703 led value
      int brightness = int(f0); 
 
  if ((x == x1 && y == y1) || 
      (x == x2 && y == y1) ||
      (x == x3 && y == y1) ||
      (x == x4 && y == y1) ||
      (x == x5 && y == y1) ||
      (x == x6 && y == y1) ||
      (x == x7 && y == y1) ||
      (x == x8 && y == y1) ||
      (x == x9 && y == y1) ||
      (x == x10 && y == y1) ||
      (x == x11 && y == y1) ||
      (x == x12 && y == y1) ||
      (x == x13 && y == y1) ||
      (x == x14 && y == y1) ||
      (x == x15 && y == y1) ||
      (x == x16 && y == y1) ||
      /////////////////////////2
      (x == x1 && y == y2) || 
      (x == x2 && y == y2) ||
      (x == x3 && y == y2) ||
      (x == x4 && y == y2) ||
      (x == x5 && y == y2) ||
      (x == x6 && y == y2) ||
      (x == x7 && y == y2) ||
      (x == x8 && y == y2) ||
      (x == x9 && y == y2) ||
      (x == x10 && y == y2) ||
      (x == x11 && y == y2) ||
      (x == x12 && y == y2) ||
      (x == x13 && y == y2) ||
      (x == x14 && y == y2) ||
      (x == x15 && y == y2) ||
      (x == x16 && y == y2) ||
      /////////////////////////3
      (x == x1 && y == y3) || 
      (x == x2 && y == y3) ||
      (x == x3 && y == y3) ||
      (x == x4 && y == y3) ||
      (x == x5 && y == y3) ||
      (x == x6 && y == y3) ||
      (x == x7 && y == y3) ||
      (x == x8 && y == y3) ||
      (x == x9 && y == y3) ||
      (x == x10 && y == y3) ||
      (x == x11 && y == y3) ||
      (x == x12 && y == y3) ||
      (x == x13 && y == y3) ||
      (x == x14 && y == y3) ||
      (x == x15 && y == y3) ||
      (x == x16 && y == y3) ||
      /////////////////////////4
      (x == x1 && y == y4) || 
      (x == x2 && y == y4) ||
      (x == x3 && y == y4) ||
      (x == x4 && y == y4) ||
      (x == x5 && y == y4) ||
      (x == x6 && y == y4) ||
      (x == x7 && y == y4) ||
      (x == x8 && y == y4) ||
      (x == x9 && y == y4) ||
      (x == x10 && y == y4) ||
      (x == x11 && y == y4) ||
      (x == x12 && y == y4) ||
      (x == x13 && y == y4) ||
      (x == x14 && y == y4) ||
      (x == x15 && y == y4) ||
      (x == x16 && y == y4) ||
      /////////////////////////5
      (x == x1 && y == y5) || 
      (x == x2 && y == y5) ||
      (x == x3 && y == y5) ||
      (x == x4 && y == y5) ||
      (x == x5 && y == y5) ||
      (x == x6 && y == y5) ||
      (x == x7 && y == y5) ||
      (x == x8 && y == y5) ||
      (x == x9 && y == y5) ||
      (x == x10 && y == y5) ||
      (x == x11 && y == y5) ||
      (x == x12 && y == y5) ||
      (x == x13 && y == y5) ||
      (x == x14 && y == y5) ||
      (x == x15 && y == y5) ||
      (x == x16 && y == y5) ||
      //////////////////////////
      (x == x1 && y == y6) || 
      (x == x2 && y == y6) ||
      (x == x3 && y == y6) ||
      (x == x4 && y == y6) ||
      (x == x5 && y == y6) ||
      (x == x6 && y == y6) ||
      (x == x7 && y == y6) ||
      (x == x8 && y == y6) ||
      (x == x9 && y == y6) ||
      (x == x10 && y == y6) ||
      (x == x11 && y == y6) ||
      (x == x12 && y == y6) ||
      (x == x13 && y == y6) ||
      (x == x14 && y == y6) ||
      (x == x15 && y == y6) ||
      (x == x16 && y == y6) ||
      /////////////////////////
      (x == x1 && y == y7) || 
      (x == x2 && y == y7) ||
      (x == x3 && y == y7) ||
      (x == x4 && y == y7) ||
      (x == x5 && y == y7) ||
      (x == x6 && y == y7) ||
      (x == x7 && y == y7) ||
      (x == x8 && y == y7) ||
      (x == x9 && y == y7) ||
      (x == x10 && y == y7) ||
      (x == x11 && y == y7) ||
      (x == x12 && y == y7) ||
      (x == x13 && y == y7) ||
      (x == x14 && y == y7) ||
      (x == x15 && y == y7) ||
      (x == x16 && y == y7) ||
      /////////////////////////
      (x == x1 && y == y8) || 
      (x == x2 && y == y8) ||
      (x == x3 && y == y8) ||
      (x == x4 && y == y8) ||
      (x == x5 && y == y8) ||
      (x == x6 && y == y8) ||
      (x == x7 && y == y8) ||
      (x == x8 && y == y8) ||
      (x == x9 && y == y8) ||
      (x == x10 && y == y8) ||
      (x == x11 && y == y8) ||
      (x == x12 && y == y8) ||
      (x == x13 && y == y8) ||
      (x == x14 && y == y8) ||
      (x == x15 && y == y8) ||
      (x == x16 && y == y8) ||
      /////////////////////////
      (x == x1 && y == y9) || 
      (x == x2 && y == y9) ||
      (x == x3 && y == y9) ||
      (x == x4 && y == y9) ||
      (x == x5 && y == y9) ||
      (x == x6 && y == y9) ||
      (x == x7 && y == y9) ||
      (x == x8 && y == y9) ||
      (x == x9 && y == y9) ||
      (x == x10 && y == y9) ||
      (x == x11 && y == y9) ||
      (x == x12 && y == y9) ||
      (x == x13 && y == y9) ||
      (x == x14 && y == y9) ||
      (x == x15 && y == y9) ||
      (x == x16 && y == y9) ||
      /////////////////////////
      (x == x1 && y == y10) || 
      (x == x2 && y == y10) ||
      (x == x3 && y == y10) ||
      (x == x4 && y == y10) ||
      (x == x5 && y == y10) ||
      (x == x6 && y == y10) ||
      (x == x7 && y == y10) ||
      (x == x8 && y == y10) ||
      (x == x9 && y == y10) ||
      (x == x10 && y == y10) ||
      (x == x11 && y == y10) ||
      (x == x12 && y == y10) ||
      (x == x13 && y == y10) ||
      (x == x14 && y == y10) ||
      (x == x15 && y == y10) ||
      (x == x16 && y == y10) ||
      /////////////////////////
      (x == x1 && y == y11) || 
      (x == x2 && y == y11) ||
      (x == x3 && y == y11) ||
      (x == x4 && y == y11) ||
      (x == x5 && y == y11) ||
      (x == x6 && y == y11) ||
      (x == x7 && y == y11) ||
      (x == x8 && y == y11) ||
      (x == x9 && y == y11) ||
      (x == x10 && y == y11) ||
      (x == x11 && y == y11) ||
      (x == x12 && y == y11) ||
      (x == x13 && y == y11) ||
      (x == x14 && y == y11) ||
      (x == x15 && y == y11) ||
      (x == x16 && y == y11) ||
      /////////////////////////
      (x == x1 && y == y12) || 
      (x == x2 && y == y12) ||
      (x == x3 && y == y12) ||
      (x == x4 && y == y12) ||
      (x == x5 && y == y12) ||
      (x == x6 && y == y12) ||
      (x == x7 && y == y12) ||
      (x == x8 && y == y12) ||
      (x == x9 && y == y12) ||
      (x == x10 && y == y12) ||
      (x == x11 && y == y12) ||
      (x == x12 && y == y12) ||
      (x == x13 && y == y12) ||
      (x == x14 && y == y12) ||
      (x == x15 && y == y12) ||
      (x == x16 && y == y12) ||
      /////////////////////////
      (x == x1 && y == y13) || 
      (x == x2 && y == y13) ||
      (x == x3 && y == y13) ||
      (x == x4 && y == y13) ||
      (x == x5 && y == y13) ||
      (x == x6 && y == y13) ||
      (x == x7 && y == y13) ||
      (x == x8 && y == y13) ||
      (x == x9 && y == y13) ||
      (x == x10 && y == y13) ||
      (x == x11 && y == y13) ||
      (x == x12 && y == y13) ||
      (x == x13 && y == y13) ||
      (x == x14 && y == y13) ||
      (x == x15 && y == y13) ||
      (x == x16 && y == y13) ||
      /////////////////////////
      (x == x1 && y == y14) || 
      (x == x2 && y == y14) ||
      (x == x3 && y == y14) ||
      (x == x4 && y == y14) ||
      (x == x5 && y == y14) ||
      (x == x6 && y == y14) ||
      (x == x7 && y == y14) ||
      (x == x8 && y == y14) ||
      (x == x9 && y == y14) ||
      (x == x10 && y == y14) ||
      (x == x11 && y == y14) ||
      (x == x12 && y == y14) ||
      (x == x13 && y == y14) ||
      (x == x14 && y == y14) ||
      (x == x15 && y == y14) ||
      (x == x16 && y == y14) ||
      /////////////////////////
      (x == x1 && y == y15) || 
      (x == x2 && y == y15) ||
      (x == x3 && y == y15) ||
      (x == x4 && y == y15) ||
      (x == x5 && y == y15) ||
      (x == x6 && y == y15) ||
      (x == x7 && y == y15) ||
      (x == x8 && y == y15) ||
      (x == x9 && y == y15) ||
      (x == x10 && y == y15) ||
      (x == x11 && y == y15) ||
      (x == x12 && y == y15) ||
      (x == x13 && y == y15) ||
      (x == x14 && y == y15) ||
      (x == x15 && y == y15) ||
      (x == x16 && y == y15) ||
      /////////////////////////
      (x == x1 && y == y16) || 
      (x == x2 && y == y16) ||
      (x == x3 && y == y16) ||
      (x == x4 && y == y16) ||
      (x == x5 && y == y16) ||
      (x == x6 && y == y16) ||
      (x == x7 && y == y16) ||
      (x == x8 && y == y16) ||
      (x == x9 && y == y16) ||
      (x == x10 && y == y16) ||
      (x == x11 && y == y16) ||
      (x == x12 && y == y16) ||
      (x == x13 && y == y16) ||
      (x == x14 && y == y16) ||
      (x == x15 && y == y16) ||
      (x == x16 && y == y16))
      /////////////////////////
     
      {
     String outString = str(x) + ',' + str(y) + ',' + str(brightness) + '\n';
     myPort.write(outString); 
      } 
}    
}
}



void keyPressed() {

  if (key=='c') {
    for (int i=0;i<gn;i++) {
      for (int j=0;j<gm;j++) {
        current[i][j] = 0;
      }
    }
  }
  if (key=='p' || key==' ') {
    pause = !pause;
  }
  if (key=='q') {
    exit();
  }
  if (key=='r') {
    RandomCells(p);
  }
}

void mouseDragged() {
  // block size
  int blockSize = 2; 
  for (int i=int(mouseX/(bx+bw)-blockSize); i<=int(mouseX/(bx+bw)+blockSize); i++) {
    for (int j=int(mouseY/(by+bw)-blockSize); j<=int(mouseY/(by+bw)+blockSize); j++) {
      if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
    }
  }
}

void mouseClicked() {
  // block size
  int i=int(mouseX/(bx+bw));
  int j=int(mouseY/(by+bw));
  if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
}
void RandomCells(float p) {
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      if (random(1)<p) {
        current[i][j] = 1;
      }
    }
  }
}

void DrawCells() {
  noStroke();
  fill(255);
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      if (current[i][j]==1) {
        rect(i*(bx+bw), j*(by+bw), bx, by);
      }
    }
  }
}

void ConwayStep() {

  int nbhdSum;

  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      nbhdSum=NeighborhoodSum(i, j);
      if (nbhdSum<2 || nbhdSum>3) next[i][j]=0;
      if (nbhdSum==3) next[i][j] = 1;
      if (nbhdSum==2) next[i][j] = current[i][j];
    }
  }
  for (int i=0;i<gn;i++) {
    for (int j=0;j<gm;j++) {
      current[i][j] = next[i][j];
    }
  }
}
 



// compute the neighborhood sum with bounds checking
int NeighborhoodSum(int i, int j) {
  int sum = 0;
  int k, l;
  for (k=i-1;k<=i+1;k++) {
    for (l=j-1;l<=j+1;l++) {
      if (k>=0 && k<gn && l>=0 && l<gm && !(k==i && l==j)) {
        sum+=current[k][l];
      }
    }
  }
  return sum;
 
}

pls first loose all the
xN yN and esp. that 255 long if()
we have the for loop so not need any of this.

so now you want send:
two numbers, separated by a comma and ended by linefeed:
a,b(lf)
with a 0 … 255
“,”
and b 0 … 4095 ( what led and arduino output is that??? )
“\n”

import processing.serial.*;
Serial myPort;
String serialName = "/dev/tty.usbmodem40915201";

void sendbright(int l,int x, int y) {
  color c = get(x, y);                          //get color data from x y point
  float br = brightness(c);                     //converts random color data to 0-255
  int led = (int)map(br, 0, 255, 0, 4095);      // converts rgb value led range??
     String outString = str(l) + ',' + str(led) + '\n';
     print(outString);
     myPort.write(outString); 
}

void loop16_16() {
  int l = 0;
  for ( int i = 0; i<16; i++) {
    for ( int k = 0; k<16; k++) {
      int x = 15 + k * 30;
      int y = 15 + i * 30;
      print("l "+l+" x "+x+" y "+y+"_send: ");
      sendbright(l, x, y);
      l++;
    }
  }
}

void setup() {
  size(500,500);
  myPort = new Serial(this, serialName, 9600);
  loop16_16();
}

void draw() {
}


when i use your original ? game ? background again:

// https://discourse.processing.org/t/sampling-color-data-for-led-matrix/8302/6

// version using a easy grid math:
// smart grid of rectangles...
int x = 15, y = x, w = 30, h = w, offset = 0;
int grid = 16, many = grid*grid;
PVector pos = new PVector(0, 0);
// 
import processing.serial.*;
Serial myPort;
String serialName = "/dev/tty.usbmodem40915201";

void get_pos(int i ) {                             // calc x/y pos and save to PVector pos
  pos.x = x+(i%grid)*(w+offset);
  pos.y = y+(floor(i/grid))*(h+offset);
}

void getsend_loop16_16() {
  for (int i = 0; i < many; i++) {
    get_pos(i);
    color c = get((int)pos.x, (int)pos.y);        // get color data from x y point
    float br = brightness(c);                     // get brightness only
    int led = (int)map(br, 0, 255, 0, 4095);      // converts rgb value led range??
    String outString = str(i) + ',' + str(led) + '\n';                            // 255,4095\n
    print("x "+pos.x+" y "+pos.y+" send: "+outString);
    myPort.write(outString);
  }
}

void setup() {
  size(500, 500);
  myPort = new Serial(this, serialName, 9600);
  frameRate(1);                                 //(10);
  setup_game();
}

void draw() {
  background(0, 0, 0);
  DrawCells();
  if (!pause) ConwayStep();
  getsend_loop16_16();
}


//________________________ use original code ? game of live ? 

int[][] current, next;
float p;                        // prob of life, 0 < p < 1
boolean pause;                 // pause toggle
// block and border vars: bx cell width in pixels, by cell height in pixels, bw border width in pixels
int bx, by, bw;
int gn, gm;  // grid size: dimensions of the 2d cell arrays

//

void setup_game() {      // kll use original variables but settings from our above grid!
  bx = w;
  by = w;
  bw = 1;
  gn = grid;
  gm = grid;
  current = new int[gn][gm];
  next = new int[gn][gm];
  for (int i=0; i<gn; i++) {
    for (int j=0; j<gm; j++) {
      current[i][j] = 0;
      next[i][j] = 0;
    }
  }  
  // life prob
  p=0.2;
  RandomCells(p);
  pause = false;
}

void keyPressed() {

  if (key=='c') {
    for (int i=0; i<gn; i++) {
      for (int j=0; j<gm; j++) {
        current[i][j] = 0;
      }
    }
  }
  if (key=='p' || key==' ') {
    pause = !pause;
  }
  if (key=='q') {
    exit();
  }
  if (key=='r') {
    RandomCells(p);
  }
}

void mouseDragged() {
  // block size
  int blockSize = 2; 
  for (int i=int(mouseX/(bx+bw)-blockSize); i<=int(mouseX/(bx+bw)+blockSize); i++) {
    for (int j=int(mouseY/(by+bw)-blockSize); j<=int(mouseY/(by+bw)+blockSize); j++) {
      if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
    }
  }
}

void mouseClicked() {
  // block size
  int i=int(mouseX/(bx+bw));
  int j=int(mouseY/(by+bw));
  if (i>=0 && i<gn && j>=0 && j<gm) current[i][j] = 1;
}

void RandomCells(float p) {
  for (int i=0; i<gn; i++) {
    for (int j=0; j<gm; j++) {
      if (random(1)<p) {
        current[i][j] = 1;
      }
    }
  }
}

void DrawCells() {
  noStroke();
  fill(255);
  for (int i=0; i<gn; i++) {
    for (int j=0; j<gm; j++) {
      if (current[i][j]==1) {
        rect(i*(bx+bw), j*(by+bw), bx, by);
      }
    }
  }
}

void ConwayStep() {
  int nbhdSum;
  for (int i=0; i<gn; i++) {
    for (int j=0; j<gm; j++) {
      nbhdSum=NeighborhoodSum(i, j);
      if (nbhdSum<2 || nbhdSum>3) next[i][j]=0;
      if (nbhdSum==3) next[i][j] = 1;
      if (nbhdSum==2) next[i][j] = current[i][j];
    }
  }
  for (int i=0; i<gn; i++) {
    for (int j=0; j<gm; j++) {
      current[i][j] = next[i][j];
    }
  }
}

// compute the neighborhood sum with bounds checking
int NeighborhoodSum(int i, int j) {
  int sum = 0;
  int k, l;
  for (k=i-1; k<=i+1; k++) {
    for (l=j-1; l<=j+1; l++) {
      if (k>=0 && k<gn && l>=0 && l<gm && !(k==i && l==j)) {
        sum+=current[k][l];
      }
    }
  }
  return sum;
}


Thanks so much for the help kll! This works perfectly.