Guest User

Untitled

a guest
Mar 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. ArrayList<PVector> history = new ArrayList<PVector>();
  2.  
  3. import processing.serial.*;
  4. float[] portValues = new float[8];
  5.  
  6.  
  7. Serial myPort;
  8. String inString;
  9.  
  10. void setup() { //set up canves
  11. size(400,400);
  12. frameRate (30);
  13. rectMode(CENTER);
  14. background(225);
  15.  
  16. myPort = new Serial(this, "/dev/cu.usbmodem1421", 9600);
  17.  
  18.  
  19. for(int i = 0; i<2; i++) { //set inatial point
  20. PVector point = new PVector(425,550);
  21. history.add(point);
  22.  
  23. portValues[i] = 0;
  24. }
  25. }
  26.  
  27.  
  28. void draw() { //finds last x and y positions and draws a line between them
  29.  
  30. fill(0);
  31. strokeWeight(2);
  32.  
  33. if (inString != null)
  34. {
  35. portValues = processSensorValues(inString);
  36. }
  37.  
  38. float z = portValues[2]/3;
  39.  
  40. float xx = map(portValues[0],-10,10,0,width);
  41. float yy = map(portValues[1],-10,10,0,height);
  42.  
  43. if(portValues[3] == 1)
  44. {
  45. PVector point = new PVector(xx,yy);
  46.  
  47. history.add(point);
  48. PVector newPt = history.get(history.size()-1);
  49. PVector oldPt = history.get(history.size()-2);
  50.  
  51. line(oldPt.x,oldPt.y,newPt.x,newPt.y);
  52. }
  53. else if(portValues[3] == 0)
  54. {
  55. }
  56.  
  57. println(inString); //prints data
  58. }
  59.  
  60. float[] processSensorValues(String valString) { //uses tempture data for nothing, but helps process data
  61.  
  62. String[] temp = new String[8];
  63. temp = split(valString,"\t");
  64.  
  65. if(temp == null) {
  66. for(int i = 0; i<8; i++) {
  67. temp[i] = "0";
  68. }
  69. }
  70.  
  71. float[] vals = new float[8];
  72. for(int i = 0; i<8; i++)
  73. {
  74. if(temp != null)
  75. {
  76. vals[i] = float(temp[i]);
  77. }
  78.  
  79. else
  80. {
  81. vals[i] = 0;
  82. }
  83.  
  84. }
  85. return vals;
  86. }
  87.  
  88. void serialEvent(Serial p) {
  89. inString = myPort.readStringUntil(10);
  90. }
Add Comment
Please, Sign In to add comment