Lab 12: Media Controller

Author: Andrew Huang

Date: May 5 2017

Partners: Jacob Park

Materials: Arduino, Potentiometer, Processing

Today, after learning about images and videos, we used Arduino and Processing to make an interaction between the two. Our Arduino Potentiometer code allowed us to control the position of the picture, and the Processing code allowed us to draw the picture of a rocket . Afterward, we decided the sound of a rocket. Some difficulties we had was accessing the right values of the values of Arduino, causing the baud rate to become unstable, but we quickly realized that our baud rate was not correct because we accessed the values outside of the while loop, and this caused the reading to be unstable. Finally, we got both the Arduino and the Processing side of the code to work properly.

The code for the lab is attached below.

Links / sources:×353.jpg


 * Load and Display 
 * Images can be loaded and displayed to the screen at their actual size
 * or any other size. 
import processing.serial.*;
import processing.sound.*;

SoundFile file;

PImage img;  // Declare variable "a" of type PImage

Serial myPort;
int valueFromArduino;

void setup() {
  size(640, 360);
  // The image file must be in the data folder of the current sketch 
  // to load successfully
  // this prints out the list of all available serial ports on your computer.
  myPort = new Serial(this, Serial.list()[ 2 ], 9600);
  img = loadImage("pslv-640x353.jpg");  // Load the image into the program 
  file = new SoundFile(this, "Rocket Launch Sound Effect.mp3");;

void draw() {
  // Displays the image at its actual size at point (0,0)
   while ( myPort.available() > 0) {
    valueFromArduino =;
  //image(img, 0, 0);
  // Displays the image at point (0, height/2) at half of its size
  image(img, 0, valueFromArduino, img.width, img.height);


// Arduino

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  delay(10);        // delay in between reads for stability

Leave a Reply