/** * Loop Video with values sent from Arduino. * * Using an Arduino and Potentiometer, contro the playback speed of a video * Recieve values using Serial I/O library */ import processing.serial.*;// import serial library float diameter = 0.0; // the speed at which the video plays float maxSpeed = 200.0; float minSpeed = 1.0; Serial myPort; // The serial port void setup() { size(600, 600); smooth(); background(0); println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 9600); } void draw() { ellipse(mouseX, mouseY, diameter, diameter); } /** * serialEvent * * This function access the values coming in from the serial port * It assigns the values to the play speed of the video, called videoSpeed * The videoSpeed has a range of -5x to +5x normal playing speed * These values are determined by the minSpeed and maxSpeed variables * If you alter them you can change the range of speed the video will play * For this to work, an Arduino must be sending one byte through the serial port */ void serialEvent (Serial myPort) { // get the byte: int inByte = myPort.read(); diameter = map(inByte, 0, 255, minSpeed, maxSpeed); // print it: println(inByte); } // This can be tested with using the keys if you are unable to access and Arduino and potentiometer // The UP key increases the speed and the DOWN key decreases the speed void keyPressed() { if(keyCode == UP) { diameter += 0.1; diameter = constrain(diameter, minSpeed, maxSpeed); } if(keyCode == DOWN) { diameter -= 0.1; diameter = constrain(diameter, minSpeed, maxSpeed); } println("adjusted diameter with keys to: " + diameter); }