Recitation 10: Image & Video

For using arduino to control the media, I came up with the idea that use light sensor to detect the light and thus change the color of an image according how bright the outside world is. Therefore, I chose to use tint() function in the processing side and analogRead() in the arduino side. I also tried to add a LED and potentiometer in the circuit but I failed and do not know why at that time and just gave up. But I now know that it is because I did not make parallel connections between them and the LDR, which makes the brightness of the LED hard to change as switching the potentiometer to different values of resistance. Here are the codes in arduino.
#include "SerialRecord.h"
SerialRecord writer(1);
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
writer[0] = sensorValue;
writer.send();
}

At the beginning, I found that my image is not presented on the sketch and I checked the codes where I show the image in the setup() function instead of draw() function. I then changed the codes to the correct ones. I also found that the color of the image changed a little bit later than the change of the light sensor. I asked Iris for help and she said that the loading of image may delay the receiving of the data. Here are the codes in processing.
PImage photo;
import processing.serial.*;
import osteele.processing.SerialRecord.*;
Serial serialPort;
SerialRecord serialRecord;
void setup(){
size(800,800);
String serialPortName = SerialUtils.findArduinoPort();
serialPort = new Serial(this, serialPortName, 9600);
serialRecord = new SerialRecord(this, serialPort, 1);
photo = loadImage("bear.jpeg");
}
void draw() {
image(photo, 0, 0, width, height);
serialRecord.read();
int value = serialRecord.get();
text(value, 100, 500);
int c = int(map(value,0,200,0,255));
tint(0,255,c);
}

Here is how the exercises works.

Leave a Reply

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