Hardware Reference
In-Depth Information
Continued from previous page.
// set initial background and smooth drawing:
background(#543174);
smooth();
// For a list of cameras on your computer, use this line:
println(Capture.list());
// use the default camera for capture at 30 fps:
myCam = new Capture(this, width, height, 30);
}
8
The draw() method paints the
camera image to the screen and adds a
timestamp.
void draw () {
// make a single number from the current hour, minute, and second:
currentTime = hour() * 3600 + minute() * 60 + second();
if (myCam.available() == true) {
// draw the camera image to the screen:
myCam.read();
set(0, 0, myCam);
// get the time as a string:
String timeStamp = nf(hour(), 2) + ":" + nf(minute(), 2)
+ ":" + nf(second(), 2) + " " + nf(day(), 2) + "-"
+ nf(month(), 2) + "-" + nf(year(), 4);
// draw a dropshadow for the time text:
fill(15);
text(timeStamp, 11, height - 19);
// draw the main time text:
fill(255);
text(timeStamp, 10, height - 20);
}
}
The main action happens in the
serialEvent() , just as shown in the
flowchart in Figure 3-14. If the sensor
reading is greater than the threshold,
the sketch takes a picture. Every five
seconds, it uploads the picture. If the
sensor reading just changed, it calls the
sendMail() method.
8
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
sensorValue = float(inString);
sensorValue = map(sensorValue, 0, 1023, 0, height);
if (sensorValue > threshold ) {
if (currentTime - lastPictureTime > pictureInterval) {
ยป
 
Search WWH ::




Custom Search