Saturday, October 13, 2012

Midterm project process - almost done!

Hey there!
We`ve finally got the Arduino to talk appropriately to Processing. We researched some more about bend sensors and we discovered that it doesn`t really fit for our goals so we decided to use pressure sensors instead. We got the Arduino to sum all the analogical inputs and then print it and send the information through  serial port to Processing. Then, it gathers the information, compares it to a threshold and randomizes the arrays of good and bad videos to play.

Video:




Arduino code:


//Declaration of variables

int bend1 = A0;
int bend2 = A1;
int bend3 = A2;
int bend4 = A3;
int sum;
int x;
int y;
int z;
int w;

void setup()
{
  Serial.begin(9600);
}

void loop()
//Print the analogical input to send to Processing
{
  x = analogRead(bend1);
  y = analogRead(bend2);
  z = analogRead(bend3);
  w = analogRead(bend4);
  sum = x+y+w+z;
  Serial.println(sum);
}

Processing code:


import processing.serial.*;
import processing.video.*;

float stotal;
Movie trololo;
Serial myPort;

void setup() {
  trololo = new Movie(this, "trololo.mp4");
  size(480,360,P2D);
  println(Serial.list());
  myPort = new Serial(this, "COM5", 9600);
  myPort.bufferUntil('\n');
}


void serialEvent(Serial myPort) {
  stotal = float(myPort.readStringUntil('\n'));


  if (stotal > 900) {
    trololo.play();
  }
}

void movieEvent(Movie trololo) {
  trololo.read();
}

void draw() {
  image(trololo,0,0);
}

No comments:

Post a Comment