Advertisement
3rdWard_Arduino

class4_Processing create circles

Feb 15th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. /**
  2. * Loop Video with values sent from Arduino.
  3. *
  4. * Using an Arduino and Potentiometer, contro the playback speed of a video
  5. * Recieve values using Serial I/O library
  6. */
  7.  
  8. import processing.serial.*;// import serial library
  9.  
  10.  
  11. float diameter = 0.0; // the speed at which the video plays
  12. float maxSpeed = 200.0;
  13. float minSpeed = 1.0;
  14.  
  15.  
  16.  
  17. Serial myPort; // The serial port
  18.  
  19. void setup() {
  20. size(600, 600);
  21. smooth();
  22. background(0);
  23. println(Serial.list());
  24. myPort = new Serial(this, Serial.list()[0], 9600);
  25. }
  26.  
  27. void draw() {
  28.  
  29. ellipse(mouseX, mouseY, diameter, diameter);
  30. }
  31. /**
  32. * serialEvent
  33. *
  34. * This function access the values coming in from the serial port
  35. * It assigns the values to the play speed of the video, called videoSpeed
  36. * The videoSpeed has a range of -5x to +5x normal playing speed
  37. * These values are determined by the minSpeed and maxSpeed variables
  38. * If you alter them you can change the range of speed the video will play
  39. * For this to work, an Arduino must be sending one byte through the serial port
  40. */
  41. void serialEvent (Serial myPort) {
  42. // get the byte:
  43. int inByte = myPort.read();
  44. diameter = map(inByte, 0, 255, minSpeed, maxSpeed);
  45. // print it:
  46. println(inByte);
  47. }
  48.  
  49. // This can be tested with using the keys if you are unable to access and Arduino and potentiometer
  50. // The UP key increases the speed and the DOWN key decreases the speed
  51. void keyPressed() {
  52. if(keyCode == UP) {
  53. diameter += 0.1;
  54. diameter = constrain(diameter, minSpeed, maxSpeed);
  55. }
  56. if(keyCode == DOWN) {
  57. diameter -= 0.1;
  58. diameter = constrain(diameter, minSpeed, maxSpeed);
  59. }
  60. println("adjusted diameter with keys to: " + diameter);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement