Arduino passes the value to the Processing display through the serial port.

Arduino passes the value to the Processing display through the serial port.

Arduino side code:

int red=255; //Create variables to store the data you need to send
int green = 2;
int blue = 3;
void setup()
{
  Serial.begin(9600);//Define a data transfer rate of 9600 bits
}
void loop()
{ 
  Serial.print(red);
  Serial.print(",");
  Serial.print(green);
  Serial.print(",");
  Serial.print(blue);
  Serial.print("\n");
  delay(1000);
}

The above red, green, blue can be replaced with the value obtained by the color sensor in practical applications.

Processing code:

import processing.serial.*;//Introducing the serial library
 
int r = 0;
int g = 0;
int b = 0;
 
Serial myPort;//Create a Serial object called "myPort"
void setup() {
  myPort = new Serial(this,"COM7", 9600);
  myPort.bufferUntil('\n');  //buffer until meet '\n', then call the event listener
  //Define myPort's port and data transfer rate
  //Should be consistent with Arduino
}
void draw() {
  background(204);
  fill(r, g, b);
  rect(30, 20, 55, 55);
}
//listen to the event. when buffer filled, run this method
 
void serialEvent(Serial p) {
  String inString = p.readString();
  print(inString);
  
  String[] list = split(inString, ',');
// list[0] is now "Chernenko", list[1] is "Andropov"...
  r = int(list[0]);
  g = int(list[1]);
  b = int(list[2]);
}

49 Replies to “Arduino passes the value to the Processing display through the serial port.”

  1. Pingback: Stargazing
  2. Pingback: 안전카지노
  3. Pingback: omiqq
  4. Pingback: Royal Online
  5. Pingback: w88 casino review
  6. Pingback: Buy CBD Products
  7. Pingback: crush switches
  8. Pingback: boyaqq
  9. Pingback: rajapoker88
  10. Pingback: www.rajaqq1.club
  11. Pingback: wayangpoker1.club
  12. Pingback: rajaqq
  13. Pingback: Malia
  14. Pingback: Vivian
  15. Pingback: www.klikdokter.com
  16. Pingback: sales training
  17. Pingback: wire qwest
  18. Pingback: fowling rules
  19. Pingback: duratrans
  20. Pingback: rajawali qq
  21. Pingback: musim qq
  22. Pingback: pasar poker
  23. Pingback: mejaqq
  24. Pingback: qiuqiu99
  25. Pingback: www.cialisis.org
  26. Pingback: link vao w88
  27. Pingback: Bildemontering
  28. Pingback: sahabatqq
  29. Pingback: Hot Wife Captions
  30. Pingback: New Moon Spells
  31. Pingback: poker 99
  32. Pingback: đăng ký fun88
  33. Pingback: meja qq

Leave a Reply