Wednesday 27 January 2010

Code Development

To tie in with my revised rational, I have changed my Processing code, so you can turn on the system, change between manually placed webcams & cameras on the internet, select a certain feed & move the image about on the screen all through inputs from Arduino.

import processing.video.*; // import theProcessing video library
import processing.serial.*; // import the Processing serial library
Serial Arduino; // The serial port
Capture webCamOne; // The webcam feed
Capture webCamTwo;
PFont font;

float xpos, ypos, manualauto, x; // Starting position of the webcam feed
int autoselect, manualselect;
float size = 700.0;

String[] feed = new String[] {
"http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg", //Adelaide Market
"http://www.cbc.ca/bc/webcam/images/webcam.jpg", // Vancouver Building Site
"http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundleEast.jpg", //Rundle Mall East & Lantern
"http://www.draperbee.com/webcam/pic/image.jpg?1262444320177", //beehive
"http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellsth.jpg" //Adelaide Bell Street South
};

String[] description = new String[]{
"Adelaide 1 Observer ONLINE",
"Vancouver Observer ONLINE",
"Adelaide 2 Observer ONLINE",
"Colony Observer ONLINE",
"Adelaide 3 Observer ONLINE",
};
PImage[] images;

void setup() {
size(678,510,P3D);

font = loadFont("01_Digit-23.vlw");
textFont(font, 23);
// List all the available serial ports & cameras
//println(Serial.list());
println(Capture.list());

webCamOne = new Capture(this, width/2, height/2, "USB PC Camera-WDM", 30);
webCamTwo = new Capture(this, width/2, height/2, "PC Camer@-WDM", 30);

Arduino = new Serial(this, Serial.list()[1], 9600);

// read bytes into a buffer until you get a linefeed (ASCII 10):
Arduino.bufferUntil('\n');

/ need as many images as we have feeds
images = new PImage[feed.length];
// initial load of images (slow);
for (int i = 0 ; i <>
images[i] = loadImage(feed[i]);
}
}

void draw() {
background(0);
if (manualauto == 1){
if (manualselect == 0){
if (webCamOne.available()){
webCamOne.read();
}
image(webCamOne, xpos, ypos);
translate(-x, 0, 0);
text("OBSERVER 1 ONLINE", 0, 494);
}
if (manualselect == 1){
if (webCamTwo.available()){
webCamTwo.read();
}
image(webCamTwo, xpos, ypos);
translate(-x, 0, 0);
text("OBSERVER 2 ONLINE", 0, 494);
}
if (manualselect == 2){
translate(-x, 0, 0);
text("OBSERVER 3 OFFLINE", 0, 494);
}
}
else{
loadImage(feed[autoselect]);
image(images[autoselect], xpos, ypos, width/2, height/2);
translate(-x, 0, 0);
text(description[autoselect], 0, 494);
}

x = x +3;
if (x > width + size){
x = -size;
}
}


void serialEvent(Serial Arduino) {
// read the serial buffer:
String myString = Arduino.readStringUntil('\n');
// 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:
int sensor[] = int(split(myString, ','));

// print out the values you got:
for (int sensorNum = 0; sensorNum <>
print("sensor " + sensorNum + ": " + sensor[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensor.length > 1) {
xpos = map(sensor[0], 0, 1023, 0, width/2);
ypos = map(sensor[1], 0, 1023, 0, (height/2 - 50));
autoselect = (int)map(sensor[2], 0, 1023, 0, images.length - 1);
manualauto = map(sensor[3], 0, 1, 0, 1);
manualselect = (int)map(sensor[4], 0, 1023, 0, 2);
}
}
}

No comments:

Post a Comment