Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. // import libraries
  2. import java.awt.Frame;
  3. import java.awt.BorderLayout;
  4. import processing.serial.*;
  5.  
  6. // Serial port to connect to
  7. String serialPortName = "COM3";
  8.  
  9.  
  10. /* SETTINGS END */
  11.  
  12. Serial serialPort; // Serial port object
  13.  
  14.  
  15. void setup() {
  16. size(900,900);
  17. noStroke();
  18.  
  19. serialPort = new Serial(this, serialPortName, 9600);
  20. }
  21.  
  22. byte[] inBuffer = new byte[50]; // holds serial message
  23.  
  24. void draw() {
  25. background(0);
  26. if (serialPort.available() > 0) {
  27. float[] x= new float[2];
  28. String myString = "";
  29. try {
  30. serialPort.readBytesUntil('r', inBuffer);
  31. }
  32. catch (Exception e) {
  33. }
  34. myString = new String(inBuffer);
  35. String[] nums = split(myString, ' ');
  36. try {
  37. x[0] = float(nums[0]); //X
  38. x[1] = float(nums[1]); //Y
  39. }
  40. catch (Exception e) {
  41. }
  42. ellipse(x[0]+500, x[1]+500, 70, 70); //+500 to make the circle in the middle of interface
  43. }
  44. }
  45.  
  46. Serial.print(xf,DEC); //méthode 1
  47. Serial.print(" ");
  48. Serial.print(yf,DEC);
  49. Serial.print('r');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement