Arduino+ Processing + Webcam

Hi there, I am currently working on a secret touch detecting door lock project which allows the user to enter when the right touch sequence is key in. However if a wrong touch sequence is key in, it will trigger the webcam to take a picture of the person. I have written most of the main code in Arduino but in order to utilize my laptop webcam to take a picture i have to go through Processing.The problem I am having right now is that each time when someone key in the wrong touch sequence the webcam will take picture all the time(like every single second) until I close the processing sketch. So instead of taking picture of the person who key in the wrong touch, I end up with a picture of the last person who closes the processing sketch. I am not very good with programming, could someone please give me some guidelines or tell me why is the program behaving in this manner and if possible give me some solutions to it. I have attached the processing sketch codes below. By the way sorry if you cant understand what I am trying to say as my English is not very good. Hope to hear from you guys soon. Thanks in advance.

[import processing.video.;
import processing.serial.
;
Capture cam;
int end = 10;
String serial;
Serial port;
void setup()
{
size(600, 300);
cam = new Capture(this, 320, 240, 30);
cam.start();
port = new Serial(this, “COM13”, 9600);
serial = port.readStringUntil(end);
serial = null;
}
void draw()
{
while (port.available() > 0)
{
serial = port.readStringUntil(end);
}
if (serial != null)
{
if(cam.available())
{
cam.read();
}
image(cam,0,0);
saveFrame(“gotcha.png”);
}
}

Post you code correctly, read the how to use the forum sticky.

While this is an arduino forum not a processing one, you never reset the string back to null once you have acted on it. That code will never read in a null string, so try:-

if (serial != null)
   { 
      if(cam.available())
      {
         cam.read();
         serial = null;
      }
      image(cam,0,0);
      saveFrame("gotcha.png");   
    }

Thanks so much for your help, it work great!! :) I have posted this discussion in processing before but no one get back to me, so I thought of getting some help from this forum instead. By the way, right now the code works in a way that it manage to capture the image of the person keying in the wrong touch for the first time, however whenever someone key in the wrong touch for the second time, the webcam will take picture of the person and replace the picture it took earlier. I want it to function in a way that whenever a person key in a wrong touch sequence, the webcam will take he/her pic without replacing the older picture which it took. How should I modify the code to fit my requirements? Thanks again for your help, appreciate it!

You replace the argument of the saveFrame function with a string varialble that you make up of a fixed part plus a number. On each capture you update the number so next time you have a different file name.

Okay, I will try that right now. Thanks again for all your help, really appreciate it :)

Hi there, this is the code which i have came up with, I tried to increment the photo number so that each time when someone key in the wrong touch sequence it will trigger the webcam to capture a picture of the person without replacing the picture it took earlier however it didn't work.

This is the code i have right now

import processing.video.*;
import processing.serial.*; 

Capture cam;
int end = 10;    
String serial;   
Serial port;  

void setup() 
{
  size(600, 300);
  cam = new Capture(this, 320, 240, 30);
  cam.start();
  port = new Serial(this, "COM13", 9600); 
  serial = port.readStringUntil(end); 
  serial = null; 
}

void draw() 
{
  while (port.available() > 0)
  { 
    serial = port.readStringUntil(end);
  }
    if (serial != null) 
    {
      int i=0;
      if(cam.available()) 
      {
        cam.read();
        serial=null;
      }
    image(cam,0,0);
    saveFrame("gotcha(i).png");
    i++;
    }
}

I think the problem is at this part as it still consider the gotcha(i) as a String. How should I edit this part of the code?

saveFrame("gotcha(i).png")

Something like this:-

static int intruderNumber =0;
String fileName = "gotcha" + nf(intruderNumber, 4) + ".png"; 
saveFrame(fileName);
intruderNumber++;

Awesome!It Works great!! XD Thank you so much for all the advice and help you gave me!You have been a great help!Appreciate it a lot :) cheers