String not converted Properly from int

This is an example of how to create a string with random numbers.

String s;
char p;

void setup()
  {
  size(475, 475); 
  fill(0);
  textSize(18);
  }

void draw()
  {
  background(255);
  s = function();
  print(s);
  println();
  println();

  for (int i=0; i<25*25; i++)
    {
    print (s.charAt(i));
    if ((i+1)%25 == 0) println();
    }
  noLoop();
  }

String function()
  {  
  String s1 = "";
  for (int y=0; y<25; y++)
    {
    for (int x=0; x<25; x++)
      {
      int i = x + y*25;
//      println(i);
      if (int(random(0, 2)) == 0)
        p = 'X';
      else 
        p = ' ';    
      s1 = s1 + p;
      text(p, 25 + 10 + x*15, y*15 + 60);
      }
    }  
  return s1;
  }

You should be able to write code to send this out the serial port and write to a text file with some effort.
I will leave the rest up to you.

Consider adding extra characters to string and check for those so you know when string starts and\or ends.

:slight_smile:

1 Like