Recitation 9 Media Controller by Barry Wang

Recitation 9 Media Controller

In this week’s recitation, I tried to make a brief test on the sensors that we would like to use in our final project. So I checked out a accelerometer and use it to control the speed that the video plays.  We hooked the accelerometer to the Arduino, and realize the communication between Arduino and Processing by serial communication.

The tilt of the accelerometer on x-axis represents the speed we would like to be. If I tilt to the left, the video plays reversely; if I stay in the middle, the video pauses; if I tilt to the right, the video plays forward. We managed to make it and it proved that this sensor is completely functional in our final project.

Here is a short test video:

Code on Arduino:

#include <LSM303D.h>
#include <Wire.h>
#include <SPI.h>

/* Global variables */
int accel[3]; // we’ll store the raw acceleration values here
int mag[3]; // raw magnetometer values stored here
float realAccel[3]; // calculated acceleration values here
float heading, titleHeading;
int v;

#define SPI_CS 10

void setup()
{
char rtn = 0;
Serial.begin(9600); // Serial is used for debugging
// Serial.println(“\r\npower on”);
rtn = Lsm303d.initI2C();
//rtn = Lsm303d.initSPI(SPI_CS);
if(rtn != 0) // Initialize the LSM303, using a SCALE full-scale range
{
// Serial.println(“\r\nLSM303D is not found”);
while(1);
}
else
{
// Serial.println(“\r\nLSM303D is found”);
}
}

void loop()
{
// Serial.println(“\r\n**************”);
//getLSM303_accel(accel); // get the acceleration values and store them in the accel array
Lsm303d.getAccel(accel);
while(!Lsm303d.isMagReady());// wait for the magnetometer readings to be ready
Lsm303d.getMag(mag); // get the magnetometer values, store them in mag

for (int i=0; i<3; i++)
{
realAccel[i] = accel[i] / pow(2, 15) * ACCELE_SCALE; // calculate real acceleration values, in units of g
}
heading = Lsm303d.getHeading(mag);
titleHeading = Lsm303d.getTiltHeading(mag, realAccel);
v = int(realAccel[0]*10)+10;
// Serial.println(v);
Serial.write(v);

delay(10); // delay for serial readability
}

Code on Processing:

import processing.video.*;
import processing.serial.*;
Movie myMovie;
Serial Port;
float value;

void setup() {
  printArray(Serial.list());
  background(0);
  size(480, 480);
  myMovie = new Movie(this, "dancing.mp4");
  myMovie.loop();
  Port = new Serial(this, "COM11", 9600);
}
void movieEvent(Movie movie) {
  myMovie.read();  
}
void draw() {    
  while ( Port.available() > 0) {
    value = Port.read();
    println(value);
  }
  image(myMovie, 0, 0);   
  float newSpeed = map(value, 0, 20, -1, 1);
  myMovie.speed(newSpeed);
} 

Reflection:

In the Computer Vision reading, the part that I am most engaged with is the Myron Krueger’s point. He states that the “entire human body ought to have a role in our interactions with computers”. This is the exact point that me and my partner try to realize in our final project. In Krueger’s Videoplace project, the interaction is carried out through motion capture. Though we can out reach that point so far, what we can try is to fit the sensors into wearings like gloves, glasses and so on to create a similar interaction process. By doing so, the traditional interaction way of using mouse and keyboard is greately improved. And that is definitely a way that we need to pursue in the upcoming future.

Leave a Reply