RECITATION 10:
codes:
Arduino:
#include "SerialRecord.h" SerialRecord writer(1); void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: int value = analogRead(A0); writer[0] = value; writer.send(); }
processing:
import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; import processing.video.*; Movie myMovie; void setup() { size(1000, 400); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 1); serialRecord.read(); int value = serialRecord.values[0]; myMovie = new Movie(this, "Jing'an.mp4"); myMovie.loop(); } void draw() { background(0); serialRecord.read(); int value = serialRecord.values[0]; float x = map(value, 0, 1024, 0, width); if (myMovie.available()) { myMovie.read(); }
I used potentiometer to control the position of the image. At first it was hard to read the potentiometer using processing, then I made some changes to the code and by trial and error, I succeeded in the end. If I was given more time, I would have made it more complex, like allowing user to control the size and color of the image using potentiometer and buttons.
Leave a Reply