Hi guys and gals,
I am working out on a smaller scale a version instillation that I am working on for an night time outdoor venue. I am taking one image that and slicing it into multiple thin vertical pieces. The pieces are then recombined into the original picture within processing. In front of each "slice" will be a sonar range finder to calculate the distance of the audience. Once someone is within range of the sonar the section corresponding to that specific sonar range finder will scroll vertically on the screen. As they get closer the piece will slow down since the distance variable will decrease.
I have a Arduino Mega running a simple analogue read program at this time tethered to a laptop which in turn is connected to a projector. Though I might look into using PMW or digital read so I can greatly increase the number of slices. With the code below I am using only 6 sensors.
1. How should I run the sonars? there should be plenty of space for each not to get in each others path, but should I still worry about one sonar detecting another signal? Recommendations?
2. Passing the data to processing should I pack it into a string and then split it up in Processing or read each sonar in sequence? I have code I can show on the processing end. How are we looking? This will be expanded to a great extent once this is running. I know I need to map the input of the sonar data so I am not scrolling these images too fast.
Processing code:
import processing.serial.*;
Serial myPort;
int numSensors = 6;
int linefeed = 10;
int sensors[];
//y positions
float y1 = 1;
float y2 = 1;
float y3 = 1;
float y4 = 1;
float y5 = 1;
float y6 = 1;
//incoming data
float read1 = 0;
float read2 = 0;
float read3 = 0;
float read4 = 0;
float read5 = 0;
float read6 = 0;
//images
PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
void setup() {
size (1080, 675);
background (0);
smooth();
PImage img1 = loadImage("part1a.jpg");
PImage img2 = loadImage("part2a.jpg");
PImage img3 = loadImage("part3a.jpg");
PImage img4 = loadImage("part4a.jpg");
PImage img5 = loadImage("part5a.jpg");
PImage img6 = loadImage("part6a.jpg");
// List all the available serial ports
println(Serial.list());
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil(linefeed);
}
void draw() {
if(sensors != null){
// if valid data arrays are not null
// compare each sensor value with the previuos reading
// to establish change
read1 = map(sensors[0], 0, 1024, 0, 5);
read2 = map(sensors[1], 0, 1024, 0, 5);
read3 = map(sensors[2], 0, 1024, 0, 5);
read4 = map(sensors[3], 0, 1024, 0, 5);
read5 = map(sensors[4], 0, 1024, 0, 5);
read6 = map(sensors[5], 0, 1024, 0, 5);
}
y1 = y1 + read1;
if (y1 >= 675) {
y1=0;
}
y2 = y2 + read2;
if (y2 >= 675) {
y2=0;
}
y3 = y3 + read3;
if (y3 >= 675) {
y3=0;
}
y4 = y4 + read4;
if (y4 >= 675) {
y4=0;
}
y5 = y5 + read5;
if (y5 >= 675) {
y5=0;
}
y6 = y6 + read6;
if (y6 >= 675) {
y6=0;
}
image (img1, 0, y1);
image (img2, 180, y2);
image (img3, 360, y3);
image (img4, 540, y4);
image (img5, 720, y5);
image (img6, 900, y6);
}
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
sensors = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
}
}
I am working out on a smaller scale a version instillation that I am working on for an night time outdoor venue. I am taking one image that and slicing it into multiple thin vertical pieces. The pieces are then recombined into the original picture within processing. In front of each "slice" will be a sonar range finder to calculate the distance of the audience. Once someone is within range of the sonar the section corresponding to that specific sonar range finder will scroll vertically on the screen. As they get closer the piece will slow down since the distance variable will decrease.
I have a Arduino Mega running a simple analogue read program at this time tethered to a laptop which in turn is connected to a projector. Though I might look into using PMW or digital read so I can greatly increase the number of slices. With the code below I am using only 6 sensors.
1. How should I run the sonars? there should be plenty of space for each not to get in each others path, but should I still worry about one sonar detecting another signal? Recommendations?
2. Passing the data to processing should I pack it into a string and then split it up in Processing or read each sonar in sequence? I have code I can show on the processing end. How are we looking? This will be expanded to a great extent once this is running. I know I need to map the input of the sonar data so I am not scrolling these images too fast.
Processing code:
import processing.serial.*;
Serial myPort;
int numSensors = 6;
int linefeed = 10;
int sensors[];
//y positions
float y1 = 1;
float y2 = 1;
float y3 = 1;
float y4 = 1;
float y5 = 1;
float y6 = 1;
//incoming data
float read1 = 0;
float read2 = 0;
float read3 = 0;
float read4 = 0;
float read5 = 0;
float read6 = 0;
//images
PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
void setup() {
size (1080, 675);
background (0);
smooth();
PImage img1 = loadImage("part1a.jpg");
PImage img2 = loadImage("part2a.jpg");
PImage img3 = loadImage("part3a.jpg");
PImage img4 = loadImage("part4a.jpg");
PImage img5 = loadImage("part5a.jpg");
PImage img6 = loadImage("part6a.jpg");
// List all the available serial ports
println(Serial.list());
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil(linefeed);
}
void draw() {
if(sensors != null){
// if valid data arrays are not null
// compare each sensor value with the previuos reading
// to establish change
read1 = map(sensors[0], 0, 1024, 0, 5);
read2 = map(sensors[1], 0, 1024, 0, 5);
read3 = map(sensors[2], 0, 1024, 0, 5);
read4 = map(sensors[3], 0, 1024, 0, 5);
read5 = map(sensors[4], 0, 1024, 0, 5);
read6 = map(sensors[5], 0, 1024, 0, 5);
}
y1 = y1 + read1;
if (y1 >= 675) {
y1=0;
}
y2 = y2 + read2;
if (y2 >= 675) {
y2=0;
}
y3 = y3 + read3;
if (y3 >= 675) {
y3=0;
}
y4 = y4 + read4;
if (y4 >= 675) {
y4=0;
}
y5 = y5 + read5;
if (y5 >= 675) {
y5=0;
}
y6 = y6 + read6;
if (y6 >= 675) {
y6=0;
}
image (img1, 0, y1);
image (img2, 180, y2);
image (img3, 360, y3);
image (img4, 540, y4);
image (img5, 720, y5);
image (img6, 900, y6);
}
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
sensors = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
}
}
2