I think this project would fall into the category of dynamic interactive as the infrared distance sensor is measuring the distance adjusted by the human. Here, technology was used to sense the distance, to transfer the signals between arduino and processing, and to finally alter the image according to the data.
This is a short term engaging interaction as after one realizes the key to the changing picture, interest is soon lost. However, the idea/vision of the image zooming in and out with depth may capture the viewer’s attention for a longer time.
If we had more time, I would have wanted to add another sensor to change the colors of the picture and have the infrared sensor run more smoothly.
code — arduino
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// int sensorValue = analogRead(A0);
// Serial.println(sensorValue);
// delay(100);
uint16_t value = analogRead (A0);
int sensorValue = analogRead (A0);
double distance = get_IR (value); //Convert the analog voltage to the distance
Serial.write(int(distance));
delay (500); //Delay 0.5s
}
//return distance (cm)
double get_IR (uint16_t value) {
if (value < 16) value = 16;
return 2076.0 / (value - 11.0);
}
code — processing
PImage img;
int rectSize = 10;
import processing.serial.*;
Serial myPort;
int valueFromArduino;
void setup() {
size (876, 550, P3D);
background(255);
printArray(Serial.list());
// this prints out the list of all available serial ports on your computer.
myPort = new Serial(this, Serial.list()[3], 9600);
}
void draw() {
// to read the value from the Arduino
img = loadImage("keke.PNG");
while ( myPort.available() > 0) {
valueFromArduino = myPort.read();
}
if (valueFromArduino>0) {
valueFromArduino=int(map(valueFromArduino, 0,40,0,width));
//url: www.thebalance.com/halloween-spending-statistics-facts-and-trends-3305716
for (int x=0; x<img.width; x=x+rectSize) {
for (int y=0; y<img.height; y=y+rectSize) {
int index = x+y*img.width;
color c =img.pixels[index];
float r = red(img.pixels[index]);
float b = blue(img.pixels[index]);
float z = map(b, 255, 0, 0, valueFromArduino);
noStroke();
fill(c);
pushMatrix();
translate(x, y, z);
rectMode(CENTER);
rect(0, 0, rectSize, rectSize);
popMatrix();
}
println(valueFromArduino);//This prints out the values from Arduino
}
}
}
Leave a Reply
You must be logged in to post a comment.