Advertisement
virae

Untitled

Nov 18th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import processing.serial.*;
  2.  
  3. int lf = 10; // Linefeed in ASCII
  4. String myString = null;
  5. Serial myPort; // The serial port
  6.  
  7. int min, max, current;
  8.  
  9. void setup() {
  10.  
  11. size(1920, 400);
  12. //frameRate(200);
  13.  
  14.  
  15. min = 1024;
  16. max = 0;
  17.  
  18. // List all the available serial ports
  19. println(Serial.list());
  20. // I know that the first port in the serial list on my mac
  21. // is always my Keyspan adaptor, so I open Serial.list()[0].
  22. // Open whatever port is the one you're using.
  23. myPort = new Serial(this, Serial.list()[0], 9600);
  24. myPort.clear();
  25. // Throw out the first reading, in case we started reading
  26. // in the middle of a string from the sender.
  27. myString = myPort.readStringUntil(lf);
  28. myString = null;
  29. }
  30.  
  31. void draw() {
  32. while (myPort.available () > 0) {
  33. myString = myPort.readStringUntil(lf);
  34. if (myString != null) {
  35. myString = trim(myString);
  36. current = parseInt(myString);
  37.  
  38. if (current > max) max = current;
  39. if (current < min) min = current;
  40.  
  41. background( map(current, min, max, 0, 255), 200, 200 );
  42.  
  43. println(current + " " + min + " "+ max);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement