Guest User

Untitled

a guest
Feb 22nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. import processing.serial.*;
  2.  
  3. float[] portValues = new float[8];
  4.  
  5. Serial myPort;
  6. String inString;
  7.  
  8. int r = 10;
  9. int g = 10;
  10. int b = 10;
  11.  
  12. float x=0;
  13. float y=0;
  14. float z=0;
  15.  
  16. void setup()
  17. {
  18. size(1000,1000);
  19. background(255);
  20.  
  21. myPort = new Serial(this, "/dev/cu.usbmodem1421",9600);
  22.  
  23. for(int i = 0; i<8; i++)
  24. {
  25. portValues[i] = 0;
  26. }
  27. }
  28. void draw() {
  29. if (inString != null) {
  30. portValues = processSensorValues(inString);
  31. }
  32. if (portValues[3]==0 && portValues[4]==1)
  33. {
  34. frameRate(15);
  35. y=random(255);
  36. x=random(255);
  37. z=random(255);
  38.  
  39. }
  40. fill(r,g,b);
  41. // Parts here were in the wrong place and used down below on the color scale and change rate, with drawing as a plus.
  42.  
  43. //ellipseMode(CENTER);
  44. //ellipse(100,300,100,155);
  45.  
  46. //fill(360,360,300);
  47. //rect(100,100,100,100);
  48.  
  49. //fill(50,360,360);
  50. //rect(350,175,100,50);
  51.  
  52. ////fill(,0,100);
  53. //rect(475,290,150,175);
  54.  
  55. fill(r,g,b);
  56. strokeWeight(1);
  57. rect(0,0,100,12);
  58. fill(225);
  59. text((r + "," +"," + b),10,10);
  60.  
  61.  
  62. //horozontal lines
  63. strokeWeight(4);
  64. line(1000,150,0,150);
  65. line(1000,200,0,200);
  66. line(1000,50,0,50);
  67. line(1000,375,0,375);
  68.  
  69.  
  70. //vertical lines
  71. line(50,0,50,0);
  72. line(50,0,50,1000);
  73. line(150,0,150,1000);
  74. line(300,0,300,1000);
  75. line(400,0,400,1000);
  76. line(550,0,550,1000);
  77.  
  78.  
  79.  
  80. float tempValue = map(portValues[7],77,86,0,255);
  81. if(portValues[3] == 1) {
  82. fill(255,300,0,tempValue);
  83. } else if(portValues[4] == 1) {
  84. fill(0,255,0,tempValue);
  85. } else {
  86. fill(0,0,255,tempValue);
  87. }
  88. ellipseMode(CENTER);
  89. ellipse(100,300,100,155);
  90.  
  91. fill(360,360,300);
  92. rect(100,100,100,100);
  93.  
  94. fill(50,360,360);
  95. rect(350,175,100,50);
  96.  
  97. //fill(,0,100);
  98. rect(475,290,150,175);
  99. float x = map(portValues[1],-10,10,0,width);
  100.  
  101.  
  102. float y = map(portValues[0],-10,10,0,height);
  103.  
  104.  
  105. //float z = map(portValues[2],-10,10,50,150); // dont think I meeded to add this, mainly for drawing piece just experementing.
  106.  
  107.  
  108. float lightValue = portValues[5];
  109.  
  110. noStroke();
  111. ellipse(x, y, 10, 10);
  112. println(inString);
  113.  
  114. }
  115.  
  116. void mouseDragged()// used to draw and change the thickness of lines when drawing but does not work if I turn off dots.
  117. {
  118. if(mouseButton == LEFT)
  119. {
  120. strokeWeight(20);
  121. stroke(r,g,b);
  122. line(pmouseX,pmouseY,mouseX,mouseY);
  123. }
  124. }
  125. void mousePressed()
  126. {
  127. if(mouseButton == RIGHT)
  128. {
  129. background(255);
  130. }
  131. }
  132.  
  133.  
  134.  
  135.  
  136. float[] processSensorValues(String valString) {
  137.  
  138. String[] temp = new String[8];
  139. temp = split(valString,"\t");
  140.  
  141. if(temp == null) {
  142. for(int i = 0; i<8; i++) {
  143. temp[i] = "0";
  144. }
  145. }
  146.  
  147. float[] vals = new float[8];
  148. for(int i = 0; i<8; i++)
  149. {
  150. if(temp != null)
  151. {
  152. vals[i] = float(temp[i]);
  153. }
  154.  
  155. else
  156. {
  157. vals[i] = 0;
  158. }
  159.  
  160. }
  161. return vals;
  162. }
  163. void serialEvent(Serial p) {
  164. inString = myPort.readStringUntil(10);
  165. }
Add Comment
Please, Sign In to add comment