Hi, the code below uses rfid to load multiple images, at the moment only the 1st image shows and I don't have a way to view the rest of them. I'm looking to add a smooth transition between the images, kind of like a slideshow.
import processing.serial.*;
import ddf.minim.*;//declare
AudioPlayer player;
Minim minim;
Serial portOne; // the first serial port
Serial portTwo; // the second serial port
boolean showImage; // whether or not to show the image
// the list of names
String[] tags = {
"5100C2F495F2","5100C2EB6F17"};
String tag="";
// the list of people
PImage thisImage;
int maxPics =5;
int pictureNumber = 1;
void setup() {
size(1000, 664);
showImage = false;
// list the serial ports
println(Serial.list());
// open the serial ports:
portOne = new Serial(this, Serial.list()[16], 9600);
// set both ports to buffer information until you get 0x03:
portOne.bufferUntil(0x03);
minim=new Minim(this);
}
void draw() {
background(255,255,255);
if(tag!="")
{
getImage(tag,pictureNumber);
image(thisImage, 0, 0);
}
// if there's an image to show, show it:
if (showImage) {
image(thisImage, 0, 0);
}
}
void serialEvent(Serial thisPort) {
// read the incoming serial data:
String inString = thisPort.readStringUntil(0x03);
// if the string is not empty, do stuff with it:
if (inString != null) {
// if the string came from serial port one:
if (thisPort == portOne) {
print ("Data from port one: ");
}
// if the string came from serial port two:
if (thisPort == portTwo) {
print ("Data from port two: ");
}
// print the string:
println(inString);
println(inString.substring(1,13)+".jpg");
// images[i] = loadImage(inString.substring(1,13)+ "/" + i + ".jpg" );
println(inString.substring(1,13)+"/music.mp3");
if(player!=null)
{
player.pause();
player.close();
}
player=minim.loadFile(inString.substring(1,13)+"/music.mp3");//locate file
println(player);
player.play();//when opened play this
// the tag ID is only bytes 1 through 13. Get it:
tag = inString.substring(1, 13);
}
}
// Get random image from the folder filelist array
void getImage(String tag,int picture) {
String filenames[];
try{
// open the directory:
File directory = new File(sketchPath("data")+"/"+tag);
// list the files in the directory:
filenames = directory.list();
int picCounter=0;
for(int thisFile = 0; thisFile<filenames.length; thisFile++){
// if the file is a .jpg:
if (filenames[thisFile].endsWith(".jpg")) {
picCounter++;
if(picCounter==picture)
{
// get the filename without the .jpg extension:
String thisName = filenames[thisFile].substring(0, filenames[thisFile].length() -4);
//if the filename matches the name of the person:
// load the image from the file:
thisImage = loadImage("data/"+tag+"/"+filenames[thisFile]);
// show it:
showImage = true;
}
}
}
}
catch(Exception f){
// if there was a problem reading the directory:
println("Image import error - missing thisFile or folder");
}
}
The code below is a way of getting images to have a smooth transition, but I am unsure on how I can add it to my code above?
int a;
PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
void setup()
{
size(1000,664,P3D); // or however big you need.
img1=loadImage("image1.jpg");
img2=loadImage("image2.jpg");
img3=loadImage("image3.jpg");
img4=loadImage("image4.jpg");
img5=loadImage("image5.jpg");
img6=loadImage("image6.jpg");
a=0;
}
void draw()
{
background(0);
noTint();
image(img1,0,0);
tint(255,255,255,a);
image(img2,0,0);
if(a<255)
a++;
}
Thanks