Recitation 10: Image & Video

Recitation Friday!This time,I will explore using physical controllers to modify the way in which media is being displayed.My method was helpful for my final project even though it was simple: using a vibration sensor to change the images on the monitor.The circuit was based on the connection between the vibration sensor and the Arduino,so it was really easy.However,I encountered two problems when it came to the coding part:one was about accidentally left commenting important codes and using “delay” in Processing and the other was about the delay in transferring data from Arduino to Processing.Later,I turned to Rudi for helped and I figured out how to revise it.

Here was how it worked.

The codes in Arduino:

#include “SerialRecord.h”
int vib_pin=7;
int led_pin=13;
SerialRecord writer(1);
void setup() {
Serial.begin(9600);
pinMode(vib_pin,INPUT);
pinMode(led_pin,OUTPUT);
}

void loop() {
int val;
val=digitalRead(vib_pin);
writer[0] = val;
//writer.send();
if(val==1)
{
digitalWrite(led_pin,HIGH);
delay(700);

// digitalWrite(led_pin,LOW);
// delay(500);
}
else
digitalWrite(led_pin,LOW);
writer.send();
delay(50);
}

The codes in Processing:

PImage photo;
import processing.serial.*;
import osteele.processing.SerialRecord.*;
int val;
Serial serialPort;
SerialRecord serialRecord;
void setup() {
  size(758, 480);
   photo = loadImage("lion-3576045__480.jpg");
  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, serialPortName, 9600);

  // If the Arduino sketch sends a different number of values, modify the number
  // `2` on the next line to match the number of values that it sends.
  serialRecord = new SerialRecord(this, serialPort, 1);
}
void draw() {
  serialRecord.read();
  int val = serialRecord.values[0];
   if(val==0){
     image(photo,0,0);
       filter(BLUR,10);
      
  }
   else if (val==1){
     image(photo,0,0);
       filter(GRAY);
      
 }
}

Author: Jinyuan Xu

Echte Liebe.

Leave a Reply

Your email address will not be published. Required fields are marked *