rjk79

Processing Serial Write

Apr 6th, 2013
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import processing.serial.*;
  2. Serial myPort;
  3. char HEADER = 'H';
  4. short LF = 10;
  5.  
  6. int slider1X;
  7. int slider2X;
  8. int slider1Y;
  9. int slider2Y;
  10. int slider1Value;
  11. int slider2Value;
  12. int prevslider1Value;
  13. int prevslider2Value;
  14. int sliderGrip;
  15. int baseX;
  16. int sliderThick;
  17.  
  18. void setup(){
  19. size(640,480);
  20. myPort = new Serial(this,Serial.list()[2],9600);
  21. baseX = width/4;
  22. slider1Y = height * 1/6;
  23. slider2Y = height * 1/2;
  24. slider1X = baseX;
  25. slider2X = baseX + 10;
  26. slider1Value = 0;
  27. slider2Value = 0;
  28. prevslider1Value = 0;
  29. prevslider2Value = 0;
  30. sliderGrip = 20;
  31. sliderThick = height * 1/6;
  32. }
  33.  
  34. void draw(){
  35. background(255,122,122);
  36. fill(0);
  37. rect(0,0,baseX,height);
  38. fill(slider1Value);
  39. rect(baseX,slider1Y,slider1Value + sliderGrip,sliderThick);
  40. fill(slider2Value);
  41. rect(baseX,slider2Y,slider2Value + sliderGrip,sliderThick);
  42. fill(122,122,122);
  43.  
  44. fill(122);
  45. rect(baseX + slider1Value,slider1Y,sliderGrip,sliderThick);
  46. rect(baseX + slider2Value,slider2Y,sliderGrip,sliderThick);
  47. if(mouseY > slider1Y && mouseY < slider1Y + sliderThick && mousePressed){
  48. slider1Value = mouseX - baseX - sliderGrip/2;
  49. }
  50. slider1Value = constrain(slider1Value,0,255);
  51. if(mouseY > slider2Y && mouseY < slider2Y + sliderThick && mousePressed){
  52. slider2Value = mouseX - baseX - sliderGrip/2;
  53. }
  54. slider2Value = constrain(slider2Value,0,255);
  55. textSize(32);
  56. fill(255);
  57. text("Yellow", 20, slider1Y + sliderThick * 2/3);
  58. text(" Red", 20, slider2Y + sliderThick * 2/3);
  59.  
  60. text(slider1Value,500,50);
  61. text(slider2Value,500,100);
  62.  
  63. if(slider1Value != prevslider1Value || slider2Value != prevslider2Value){
  64. myPort.write(slider1Value);
  65. myPort.write(",");
  66. myPort.write(slider2Value);
  67. }
  68.  
  69. prevslider1Value = slider1Value;
  70. prevslider2Value = slider2Value;
  71. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×