Recitation 10: Media Controller

  1. I connect the circuit according to the potentiometer example, and I also finish the code by using the example.
  2. The things that I learned are that I reviewed how to use float and serial records, and I also learned how to connect the speed of the video.
  3. I think my failure is that it takes me a long time to finish this project, it should be faster because this project is not that difficult. I think the thing I succeed in is that my potentiometer controls the image very well.

 

Arduino code:

/*
SendMultipleValues

Reads an analog input on pin 0, and sends a record that contains two values:

1. Value of `millis()`, modulo 1024.
2. The analog value that is read from pin 0.

If you attach a potentiometer to pin 0, you can control this value by moving
the pot.

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

Things to try:
– Connect a second potentiometer to the Arduino, and send the values from both
potentiometers, instead of send a value that is based on `millis()`.
– Send the value from another sensor, such as temperature or proximity.

by Oliver Steele, 2020-2022

This example code is in the public domain.
*/

#include “SerialRecord.h”

// Change this number to send a different number of values
SerialRecord writer(1);

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

void loop() {
int sensorValue = analogRead(A0);

writer[0] = sensorValue;
//writer[1] = 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:

/**
* Example sketch for the SerialRecord library for Processing.
*
* Receives two integers from the serial port, and uses them to control the x
* and y position of a circle on the canvas.
*/

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

Serial serialPort;
SerialRecord serialRecord;

void setup() {
background(0);
size(500, 500);
myMovie = new Movie(this, “Jing’an.mp4”);
myMovie.loop();

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();
println(serialRecord);
int value1 = serialRecord.values[0];
//int value2 = serialRecord.values[1];

//float x = map(value1, 0, 1024, 0, width);
//float y = map(value2, 0, 1024, 0, height);

image(myMovie, 0, 0);
float newSpeed = map(value1, 0, 1024, 0.1, 8);
myMovie.speed(newSpeed);
}

Movie myMovie;

 

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

 

Leave a Reply

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