Recitation 10: Image & Video

The codes for this recitation was rather easy.  I didn’t meet fatal troubles, but one significant thing did strike me, that the high frequency of Arduino’s sending info to Processing does not necessarily result in fast response in Processing. Instead, it was rather important to choose the right frequency of sending info by adequate “delay(m).”

Video:

code for Processing: 

import processing.video.*;
import processing.serial.*;
import osteele.processing.SerialRecord.*;

Serial serialPort;
SerialRecord serialRecord;

String[] cameras = Capture.list();
Capture cam;

void setup() {
  size(640, 480);
  printArray(cameras);
  cam = new  Capture(this, "pipeline:autovideosrc");
  cam.start();
  
  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, serialPortName, 9600);
  serialRecord = new SerialRecord(this, serialPort, 1);

}

void draw() {
  if (cam.available()) {
    cam.read();
  }
  serialRecord.read();
  int value = serialRecord.get();
  float x = map(value,0,1000,0,255);
  image(cam, 0, 0);
  x = int(x);
  tint(x);
  
}

code for Arduino:

#include "SerialRecord.h"
SerialRecord writer(1);
int rest = A0;


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


void loop() {
int X = analogRead(rest);
writer[0] = X;
writer.send();
delay(20);
}

Leave a Reply

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