Wednesday, November 30, 2016

Mini-Project 2: Getting Stuff to Work

For the servo, I started out with a potentiometer, just to make sure the servo was actually changing speed. Demonstration.

For the camera, I had trouble getting it to continuously detect motion. The source code has it stop so that it can write the picture it takes, but I needed it to continue detecting motion as long as something was moving in front of it.

The main issue was that I was phrasing it as two separate if-statements, so that it would constantly switch between motion and no motion for each new input. Using an if, else if statement worked:

 if (cam.motionDetected()) {
   Serial.println("Motion!");
   cam.setMotionDetect(false);
   digitalWrite(ledPin, HIGH);
   s.write(103);
   delay(200);
   cam.resumeVideo();
   cam.setMotionDetect(true);
 } else if (! cam.motionDetected()) {
   Serial.println("Still.");
   digitalWrite(ledPin, LOW);
   s.write(92);
   delay(200);  
 } else {
  s.write(92);
 }

However, I also had to -- once the camera detected movement -- tell it to stop detecting movement. These three lines
   cam.setMotionDetect(false);
   cam.resumeVideo();
   cam.setMotionDetect(true);
disable and enable the motion detection. Without it, the camera continued to switch back and forth between detecting motion and no motion even with constant motion in front of the camera. I suppose it stops the else if part from being executed.

The s.write(); refers to the servo speed.

No comments:

Post a Comment