Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // this listens for: PHOTO on the serial port (from the XBee)
  2. const int CAMERA_FOCUS = 12; // yellow wire
  3. const int CAMERA_SHOOT = 11; // red wire
  4. //const int PHOTO_BUTTON = 10;
  5. const int INDICATOR    = 9;
  6. boolean trigger = false;
  7. int ix=0;
  8. char rs[12];
  9. String recieved = "";
  10.  
  11. void takePhoto() {
  12.   // trigger the camera,
  13.   //
  14.   // you may need to alter the delay() settings for your camera
  15.   // If you try to take a photo before the camera is ready, the camera will
  16.   // not take a photo. This also applies if the camera cannot focus.
  17.   if (trigger == false) {
  18.     trigger = true;
  19.     digitalWrite(CAMERA_FOCUS, HIGH);  // wake up the camera
  20.     delay(300);
  21.     digitalWrite(CAMERA_FOCUS, LOW);  
  22.     delay(400);
  23.     digitalWrite(CAMERA_SHOOT, HIGH);  // take photo
  24.     delay(300);
  25.     digitalWrite(CAMERA_SHOOT, LOW);    
  26.   }
  27.   else {
  28.     digitalWrite(CAMERA_FOCUS, LOW);
  29.     digitalWrite(CAMERA_SHOOT, LOW);    
  30.   }
  31.   trigger = false;    
  32.   return;
  33. }
  34.  
  35. boolean validChar(char c) {
  36.   // filter to process charchetrs 0-9, A-Z, a-z, newline, space and full-stop
  37.   if (c == '\n' || c == ' ' || c == '.') {
  38.     return true;
  39.   }  
  40.   if (c >= '0' && c <= '9') {
  41.     return true;
  42.   }
  43.   if (c >= 'A' && c <= 'Z') {
  44.     return true;
  45.   }
  46.   if (c >= 'a' && c <= 'z') {
  47.     return true;
  48.   }
  49.   return false;
  50. }
  51.  
  52. void setup() {    
  53.  
  54.   Serial.begin(9600);
  55.   pinMode(CAMERA_FOCUS, OUTPUT);      
  56.   pinMode(CAMERA_SHOOT, OUTPUT);  
  57.   pinMode(INDICATOR, OUTPUT);   // indicator shows activity on the serial port
  58.   //pinMode(PHOTO_BUTTON, INPUT);
  59.   digitalWrite(CAMERA_FOCUS, LOW);
  60.   digitalWrite(CAMERA_SHOOT, LOW);
  61.  
  62.   digitalWrite(INDICATOR, HIGH);
  63.   delay(300);
  64.   digitalWrite(INDICATOR, LOW);  
  65.   Serial.println("\n\nCAMERA READY");  
  66.   delay(300);
  67. }
  68.  
  69.  
  70. void loop() {
  71.  
  72.   if (Serial.available()  > 0) {
  73.       digitalWrite(INDICATOR, HIGH);
  74.       char c = Serial.read();      
  75.       if (validChar(c) == true && ix < 11) {    
  76.         rs[ix++] = c;
  77.         rs[ix] = '\0';
  78.       }      
  79.      
  80.       if ((c == '\n' || c == '\r') && ix > 2) {          
  81.         recieved = String(rs);  
  82.         if (recieved == "PHOTO" || recieved == "\nPHOTO") {
  83.           digitalWrite(INDICATOR, LOW);
  84.           takePhoto();
  85.           Serial.println("PHOTO OK");  
  86.         }  
  87.         ix = 0;
  88.       }
  89.       else if ((c == '\n' || c == '\r') && ix < 1) {
  90.         ix = 0;
  91.       }
  92.     }
  93.     else {
  94.       digitalWrite(INDICATOR, LOW);
  95.     }      
  96.   delay(50);      
  97.  
  98. }