Recitation 10: Image & Video

I used a potential meter, sent the value of its resistance to processing to change the color of the tint of the captured video. I learn from my classmate that I can also change the speed of the video playing by physica computing, which is very helpful for my final project.

code:

Arduino:

/*
  SendSingleValue

  This sketch repeatedly sends a record that contains a single value. The value
  is the value of `millis()`, modulo 32768.

  This sketch pairs well with the ReceiveSingleValue example from the
  Processing SerialRecord library
  <https://osteele.github.io/Processing_SerialRecord/>.

  You can also use the Serial Monitor to inspect the values that the sketch
  sends to the serial port.

  Things to try:
  - Connect a potentiometer to the Arduino, and send its value instead.

  by Oliver Steele, 2020-2022

  This example code is in the public domain.
*/

#include "SerialRecord.h"

SerialRecord writer(1);

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

void loop() {
  float sensorValue;
  sensorValue = analogRead(A0);
  
  writer[0] = sensorValue;
  writer.send();

  // This delay slows down the loop, so that it runs less frequently. This can
  // make it easier to debug the sketch, because new values are printed at a
  // slower rate.
  delay(10);
}

Processing:

import processing.video.*; 
String[] cameras = Capture.list();
Capture cam;
import processing.serial.*;
import osteele.processing.SerialRecord.*;

Serial serialPort;
SerialRecord serialRecord;
void setup() { 
  size(640, 480); 
  cam = new Capture(this, cameras[0]);
  cam.start(); 
  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, serialPortName, 9600);
  serialRecord = new SerialRecord(this, serialPort, 1);
} 

void draw() { 
  serialRecord.read();
  noStroke();
  float value = serialRecord.get();
  float colorRed = map(value,0,1024,0,255);
  capture();
  fill(colorRed,255-colorRed,100,60);
  rect(0,0,320,240);
  fill(255-colorRed,colorRed,100,60);
  rect(320,240,320,240);
  fill(100,colorRed,255-colorRed,60);
  rect(0,240,320,240);
  fill(100,255-colorRed,colorRed,60);
  rect(320,0,320,240);
  
}
void capture(){
  if (cam.available()) { 
   cam.read(); 
  } 
  pushMatrix();
  translate(cam.width, 0);
  scale(-1,1);


  image(cam, 0, 0);
  popMatrix();}

Leave a Reply

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