We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Can someone help me?
I'm new to processing.i'm trying to write a code that will receive arduino serial data and take a webcam photo if a value goes high.I've written the code but its giving an error "unexpected token :void". here's the code. please help.
import java.awt.Robot; import java.awt.event.KeyEvent; import java.awt.AWTException; Robot robot; import processing.serial.*; import processing.video.*; Serial myPort; int val; int number = 0; Capture cam; float value; int read; void setup() { try{ robot=new Robot(); } catch (AWTException e){ e.printStackTrace(); exit(); } size(640, 480); String portName=Serial.list()[0]; myPort=new Serial(this,portName,9600);
String[] cameras = Capture.list();
if (cameras.length == 0) { println("There are no cameras available for capture."); exit(); } else { println("Available cameras:"); for (int i = 0; i < cameras.length; i++) { println(cameras[i]); }
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, cameras[0]);
cam.start();
}
}
void draw() { if (cam.available() == true) { cam.read(); } image(cam, 0, 0); // The following does the same, and is faster when just drawing the image // without any additional resizing, transformations, or tint.
val=myPort.read(); if(val>120){ robot.keyPress(KeyEvent.VK_SPACE); //If we want a delay here, that gets a little bit more complicated... robot.keyRelease(KeyEvent.VK_SPACE); } void keyPressed() { //Detect space key presses (to show that it works) if(key == ' ') { save(screen.jpg); } }
Answers
Please make your code readable by hitting ctrl+t in processing then when pasting here, highlight it and click the C button (ctrl+o). Make sure there is one white line before and after the code.
https://forum.processing.org/two/discussion/32/how-to-format-text-and-code-on-the-new-forum/p1
Your error is usually a syntax error. Try looking for missing ";" or too little or too much {}. Ctrl+t helps you find the error.
Missing } after line 55.
i've edited the code . i want to add a command that will read the arduino input "val" through serial and take a photo through the webcam if 'val' goes higher than 120. how can i do that?
What do you want to do with the photo after you've taken it? Just display it on the screen?
Can you write code so that you print some message to the console when val is above 120?
its a security system.I want to save the photo when the 'val' from arduino goes above 120.
i am sending 'val' from arduino to processing through serial but i am unable to save the photo when 'val' goes above 120.
So you want to save the photo to disc?
This one compiles but you'll have to check and debug yourself:
It works ! thanks a lot.