I'm getting closer - I now get the error: "NullPointerException" in the line:
image(images[picture], xpos, ypos, width/2, height/2);
The goal of the program is to switch between live web cam feeds when a potentiometer is rotated.
Here's my (slightly modified) code again:
Code:
import processing.video.*; // import theProcessing video library
import processing.serial.*; // import the Processing serial library
Serial Arduino; // The serial port
Capture webCam; // The webcam feed
PFont font;
float xpos, ypos, onoff, x; // Starting position of the webcam feed
int picture, scrolltext;
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());
webCam = new Capture(this, width/2, height/2, "USB PC Camera-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');
images = new PImage[feed.length];
}
void draw() {
background(0);
if (webCam.available()){
webCam.read();
}
if (onoff == 1){
image(webCam, xpos, ypos);
translate(-x, 0, 0);
text("Camera One Online", 0, 494);
}
else{
images[picture] = loadImage(feed[picture]);
image(images[picture], xpos, ypos, width/2, height/2);
translate(-x, 0, 0);
text(description[picture], 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 < sensor.length; 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));
picture = (int)map(sensor[2], 0, 1023, 0, images.length - 1);
onoff = map(sensor[3], 0, 1, 0, 1);
scrolltext = (int)map(sensor[4], 0, 1023, 0, description.length - 1);
}
}
}