shapingthings

ReadSerial_Processing

Jun 15th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import processing.serial.*;
  2.  
  3. Serial myPort; // our serial port
  4.  
  5. String string1 = "";
  6. String string2 = "";
  7.  
  8. color bgColor = color( 255 ); // color of background
  9.  
  10. void setup() {
  11. size( 800, 600 );
  12. background( bgColor ); // set the background color\
  13.  
  14. // prints the serial ports so you can choose the correct number below
  15. printArray(Serial.list());
  16.  
  17. // your port will be different to the 11 below
  18. myPort = new Serial(this, Serial.list()[11], 9600);
  19.  
  20. myPort.bufferUntil(10);
  21. }
  22.  
  23. void draw() {
  24. // loop for displaying on the screen we are not using this here
  25. textSize(32);
  26. // display values on screen
  27. background( bgColor ); // set the background color
  28. fill(0, 102, 153, 51);
  29. text(string1, 10, 30);
  30. text(string2, 10, 60);
  31. }
  32.  
  33. void serialEvent(Serial p) {
  34. String inString = p.readString(); // read in the string
  35. String pairs[] = split( inString, ';' ); // split up string into pairs
  36. println(pairs[0]+","+pairs[1]); // print to the monitor below
  37.  
  38. string1 = pairs[0];
  39. string2 = pairs[1];
  40. }
Advertisement
Add Comment
Please, Sign In to add comment