Advertisement
Guest User

Untitled

a guest
May 29th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import processing.serial.*;
  2. import cc.arduino.Arduino;
  3.  
  4.  
  5. Arduino arduino;
  6. PFont font;
  7. int xPos=0;
  8. boolean firstLoop = true;
  9. String arduinoPort = "/dev/tty.usbserial-A6008cpG";
  10.  
  11. void setup(){
  12. size(1000,300);
  13. smooth();
  14. String ports[];
  15. ports = Arduino.list();
  16. for(int i=0;i<ports.length;i++) {
  17. if (ports[i].equals(arduinoPort)) {
  18. arduino = new Arduino(this, ports[i]);
  19. }
  20. }
  21. if (arduino == null) {
  22. throw new RuntimeException("could not find Arduino port");
  23. }
  24.  
  25. font = loadFont("MinimaSSK-96.vlw");
  26. textFont(font, 48);
  27.  
  28. background(0);
  29. }
  30.  
  31. void draw(){
  32. if (firstLoop) {
  33. delay(1500);
  34. firstLoop = false;
  35. }
  36.  
  37. int value = arduino.analogRead(0);
  38. int yPos = (int)map(value, 0, 1023, height, 20);
  39. xPos++;
  40.  
  41. if (xPos > width) {
  42. fill(0);
  43. noStroke();
  44. rect(min(xPos+30, width-100), max(yPos-70, 0), 100, 45);
  45. xPos = 0;
  46. }
  47.  
  48. fill(30, 5);
  49. noStroke();
  50. rect(0, 0, width, height);
  51.  
  52. fill(0);
  53. rect(xPos, 1, 160, height-2);
  54. rect(min(xPos+30, width-100), max(yPos-70, 0), 100, 45);
  55.  
  56. plot(xPos, yPos, value);
  57.  
  58. fill(255);
  59. text(""+value, min(xPos+30, width-100), max(yPos-30, 40));
  60.  
  61. noFill();
  62. stroke(128);
  63. rect(0, 0, width-1, height-1);
  64.  
  65. }
  66.  
  67. void plot(int x, int y, int value) {
  68.  
  69. fill(255, map(value, 0, 1023, 255, 0), 0);
  70. ellipse(x, y, 30, 30);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement