Slideshow problems
in
Integration and Hardware
•
10 months ago
Hi guys, I really need your help and is what you would consider a newbie at processing so bare with me.
I am creating a slideshow with 15 different images (5 images split in half and 5 background images) that should be projected onto two sliding doors. The idea is that when the first door opens, the initial picture will split in half and slide out with the doors, and after this, the next image should be projected onto the door behind that is not opened yet. The images will be controlled by an open and a close switch.
The problem with the code right now is that the images are selected randomly, and that the background is just black. This is where I would like another image to be projected.
The images should load in this way:
moonwalk1a.jpg +moonwalk1b.jp
- and when these slide away a new image, lets call it moonwalkbackground1.jpg should be projected.
When the doors then are triggered again by the "closed door switch" moonwalk2a +moonwalk2b should slide in and be projected and then moonwalkbackground2 etc.
I really hope someone can help and understand my question!
Here is my code as it looks now:
/* REMOVE THIS LINE TO ENABLE ARDUINO
import processing.serial.*;
import cc.arduino.*;
// For demo the arduino-parts are commented out.
REMOVE THIS LINE TO ENABLE ARDUINO */
/**
* The code is loosely based on the 'Load and Display'-example from Processing.
* It lends from the Arduino-Firmata sketch and the Firmata standard must be
* loaded on the Arduino.
*/
// Arduino arduino;
PImage[] img;
boolean doorContactOpening = false; // variables for the door sensors.
boolean doorContactClosing = false;
int openDoor = 0; // variable for the degree of which the door is open
int doorSpeed = 3; // Setting the speed of the doors
long lastUpdate;
int currentImage = 1;
void setup() {
size(640, 360);
/* REMOVE THIS LINE TO ENABLE ARDUINO
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(2, Arduino.INPUT);
arduino.pinMode(3, Arduino.INPUT);
REMOVE THIS LINE TO ENABLE ARDUINO */
// The image files must be in the data folder of the current sketch
// to load successfully
img = new PImage[10];
img[0] = loadImage("moonwalk1a.jpg"); // Load the images into the program
img[1] = loadImage("moonwalk1b.jpg");
img[2] = loadImage("moonwalk2a.jpg");
img[3] = loadImage("moonwalk2b.jpg");
img[4] = loadImage("moonwalk3a.jpg");
img[5] = loadImage("moonwalk3b.jpg");
img[6] = loadImage("moonwalk4a.jpg");
img[7] = loadImage("moonwalk4b.jpg");
img[8] = loadImage("moonwalk5a.jpg");
img[9] = loadImage("moonwalk5b.jpg");
lastUpdate = millis();
}
void draw() {
if (openDoor >= (width/2)){
currentImage = int(random(0,5));
}
/* REMOVE THIS LINE TO ENABLE ARDUINO
if (arduino.digitalRead(2) == Arduino.HIGH){
doorContactOpening = true;
doorContactClosing = false;
} else {
doorContactOpening = false;
}
if (arduino.digitalRead(3) == Arduino.HIGH){
doorContactClosing = true;
doorContactOpening = false;
} else {
doorContactClosing = false;
}
REMOVE THIS LINE TO ENABLE ARDUINO */
background(0);
if (millis()-lastUpdate > 1){
if (doorContactOpening == true){
if(openDoor<(width/2)){
openDoor += doorSpeed;
}
image(img[currentImage*2],-openDoor, 0);
image(img[currentImage*2+1],(width/2)+openDoor, 0);
} else if (doorContactClosing == true){
if(openDoor>0){
openDoor -= doorSpeed;
}
image(img[currentImage*2],-openDoor, 0);
image(img[currentImage*2+1],(width/2)+openDoor, 0);
} else {
image(img[currentImage*2],-openDoor, 0);
image(img[currentImage*2+1],(width/2)+openDoor, 0);
}
lastUpdate = millis();
} else {
image(img[currentImage*2],-openDoor, 0);
image(img[currentImage*2+1],(width/2)+openDoor, 0);
}
}
void keyPressed()
{
if( key == 'o') {
doorContactClosing = false;
doorContactOpening = true;
} else if( key == 'c') {
doorContactOpening = false;
doorContactClosing = true;
}
}
1