Categories
interaction lab recitations

Media Controller

During this recitation I did not encounter any issues with setting up the potentiometer that would control the intensity of the tint applied to the video. This took me about 30 minutes. After that, I was struggling with the button that would not work correctly. When I sought help, it turned out that nothing was wrong with my code, it was just some unknown malfunction. This issue remained unresolved…

The video of button malfunction:

The video of working potentiometer:

The Processing Code:

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


Serial serialPort;
SerialRecord serialRecord;

boolean buttonWasPressed = false;

void setup() {
  size(512, 288);
  myMovie = new Movie(this, "Jing'An.mp4"); 
  myMovie.loop();

  size(500, 500);

  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, 2);
  background(0);

}

void draw() {
  if (myMovie.available()) {
        myMovie.read();
  }

  serialRecord.read();
  int potentiometerValue = serialRecord.values[0];
  int buttonState = serialRecord.values[1];
  
  println(buttonState);
  
  if (potentiometerValue == 1023){
    filter(INVERT);
    image(myMovie, 0, 0);
  }
  else{
  float filterValue = map(potentiometerValue, 0, 1023, 0, 255);
  tint(filterValue, 0,0);
  image(myMovie, 0, 0);
  //if (buttonState == 1){
  //  tint(filterValue, 0, 0);
  //  image(myMovie, 0, 0);
  //  buttonWasPressed = true;
  //} else if (buttonState == 0 && buttonWasPressed == false){
  //  fill(255);
  //  rect(0, 0, width, height);
  //}
  }
}

The Arduino Code (just SendMultipleValues code with corrections):

#include "SerialRecord.h"

// Change this number to send a different number of values
SerialRecord writer(2);
int BUTTON_PIN = 9;

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT);
}

void loop() {
  int potentiometerValue = analogRead(A0);
  writer[0] = potentiometerValue;
  writer[1] = digitalRead(BUTTON_PIN);
  // if (digitalRead(BUTTON_PIN) == HIGH){
  //   writer[1] = 2;
  // }
  // else {
  //   writer[1] = 1;
  // }
  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.
}

The rest of the recitation (like 15 min) I ended up just working on my final project. 

Leave a Reply

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