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: 

https://www.youtube.com/watch?v=KfYto9Szei8https://www.extremetech.com/wp-content/uploads/2017/02/pslv-640×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
   printArray(Serial.list());
  // 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");
  file.play();
  file.loop();
}

void draw() {
  // Displays the image at its actual size at point (0,0)
   while ( myPort.available() > 0) {
    valueFromArduino = myPort.read();
    println(valueFromArduino);
  }
  background(0);
  //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:
  Serial.begin(9600);
}

// 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:
  Serial.write(sensorValue);
  delay(10);        // delay in between reads for stability
}

Leave a Reply