how to write data row wise in serial communication

偶尔善良 提交于 2019-12-13 02:43:38

问题


i am creating a binary image using processing IDE. and send this binary value of image to arduino through serial communication. image is in binary form and serial communication is working. but in this code int value of i and String value of s in serial communication write value from 0 ->10000; but i want to send row wise value of image.

 import processing.serial.*;
  Serial myPort; 
  PImage img;
  PImage img1;
  PrintWriter output;
  String s;
  int i,j;

  void setup()
   {


     img = loadImage("vl.png");
     size(100,100);   
     img.loadPixels();
     output = createWriter("danish.txt");
     myPort = new Serial(this, "COM6", 115200);
    noLoop();
  }

  void draw()
  {
   image(img, 0, 0,100,100);
   for (int y=0; y<height; y++)
   {
      for (int x=0; x<width; x++)

     {
         i= x+y*width;   
        if (img.pixels[i] == color(0,0,0))
  {

   i=1;

  } else 
  { 

   i=0;

  }

 String s = str(i);

  print(s);
  myPort.write(s);



 }
 if(img.pixels.length > img.width)
  {

    print("\n");
  }


 }


}

0101010101010101010101010 0101010101010101010101010 0101101010101010101010101

i want to send serial data like this row wise. please provide some solution which are helpful for me. and in advance thanks for your help and support

来源:https://stackoverflow.com/questions/56687015/how-to-write-data-row-wise-in-serial-communication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!