///////////////////////////////////////////////////////////////////////////////////// // TomatoCam v1.0 by Bryan Zimmer // http://www.bryanzimmer.net // Released 1-10-2009 ///////////////////////////////////////////////////////////////////////////////////// int picture_interval = 60; // minutes between pictures. if setting to seconds you must account for time to start up and shut down camera. int dusk = 100; // 0 - 1024 is dark to light int powerPinTime = 1000; // milliseconds to hold down the power button int shutterPinTime = 2500; // milliseconds to hold down the shutter button int powerPin = 9; // power button connected to digital pin 9 int shutterPin = 10; // shutter button connected to digital pin 10 int ledPin = 13; // led connected to digital pin 13 int lightPin = 0; // photoresistor connected to analog pin 0 int light = 0; // current light level int time = 0; // seconds since last shutter release int first_run = 1; // first run of loop sets off a test run no matter what extern volatile unsigned long timer0_millis; // needed for resetting millis() ///////////////////////////////////////////////////////////////////////////////////// void setup() { pinMode(ledPin, OUTPUT); // configure output pins pinMode(powerPin, OUTPUT); pinMode(shutterPin, OUTPUT); digitalWrite(powerPin, LOW); // set output to zero/low/off digitalWrite(shutterPin, LOW); digitalWrite(ledPin, LOW); Serial.begin(9600); delay(5000); } ///////////////////////////////////////////////////////////////////////////////////// void loop() { Serial.print("Light: "); // print debugging info to the console Serial.print(light); Serial.println(); Serial.print("Minutes: "); Serial.print(time); Serial.println(); Serial.println(); time = millis() / 1000 / 60; // read current time in minutes light = analogRead(lightPin); // read value from the light sensor if ( (light <= dusk && time >= picture_interval) || (first_run == 1) ) { digitalWrite(ledPin, HIGH); // turn on led digitalWrite(powerPin, HIGH); // turn on camera by holding down power button delay(powerPinTime); digitalWrite(powerPin, LOW); digitalWrite(ledPin, LOW); delay(3000); digitalWrite(ledPin, HIGH); // turn on led digitalWrite(shutterPin, HIGH); // take a picture by holding down the shutter button delay(shutterPinTime); digitalWrite(shutterPin, LOW); digitalWrite(ledPin, LOW); resetMillis(); // use this to avoid the millis() overflow at 9.5 hours time = 0; // start timer over again first_run = 0; delay(3000); digitalWrite(powerPin, HIGH); // turn off camera delay(powerPinTime); digitalWrite(powerPin, LOW); } } ///////////////////////////////////////////////////////////////////////////////////// void resetMillis() // use this to avoid the millis() overflow at 9.5 hours { cli(); // disable interrupts timer0_millis = 0; sei(); // enable interrupts } /////////////////////////////////////////////////////////////////////////////////////