// Intervalometer with Pot // by MauricioC90 // Instructables.com // #include #include LiquidCrystal_I2C lcd(0x27,16,2); const int buttonSelectPin = 3; // the number of the pushbutton pin const int buttonEnterPin = 4; const int potReadPin = A0; const int shutterPin = 13; unsigned long potValue = 0; unsigned long timeInterval = 0; // time interval for shutter in secs, limited from 5 to 999 secs unsigned long interval = 0; unsigned long timeLapse = 0; // how long in minutes will be tacking pictures, limited to 999 mins unsigned long totalShots = 0; // how many shots i.e.: timeLapse / timeInterval String stringOne = ""; // user for concatenation of strings String stringTwo = ""; String stringThree = ""; unsigned long shutterDelay = 100; // keep shutter on by milisecs. void setup() { pinMode(buttonSelectPin, INPUT); pinMode(buttonEnterPin, INPUT); pinMode(shutterPin, OUTPUT); lcd.init(); lcd.backlight(); // Turn on the backligt (try lcd.noBaklight() to turn it off) lcd.setCursor(0,0); //First line lcd.print("Intervalometer"); lcd.setCursor(0,1); //Second line lcd.print("Push Any button"); while (!digitalRead(buttonSelectPin) && !digitalRead(buttonEnterPin)) {} // wait for any button } // the loop function runs over and over again forever void loop() { delay(500); // to avoid double command while(true) { showParameters(); // shows the interval and the total time lcd.setCursor(0,1); lcd.print("Sel or Enter"); while (!digitalRead(buttonSelectPin) && !digitalRead(buttonEnterPin)) {} // wait for any button if (digitalRead(buttonSelectPin)) { //get parameter for time-lapse delay(500); // to avoid double command timeInterval = getTimeInterval(); timeLapse = getTimeLapse(); delay(500); // to avoid double command } if (digitalRead(buttonEnterPin)) { if (timeInterval > 0 && timeLapse > 0) { totalShots = timeLapse * 60 / timeInterval; startTimeLapse(totalShots, timeInterval*1000); } } } } // shows two variables of time lapse in display void showParameters(void){ lcd.clear(); lcd.setCursor(0,0); stringOne = "i:"; stringTwo = " L:"; stringThree = stringOne + timeInterval + "s "+ stringTwo + timeLapse + "min"; lcd.print(stringThree); } int getTimeInterval(void) { delay(500); lcd.clear(); lcd.setCursor(0,0); lcd.print("Use pot + Enter"); lcd.setCursor(0,1); lcd.print("i (secs): "); while(!digitalRead(buttonEnterPin)){ // select value until Enter lcd.setCursor(10,1); potValue = analogRead(potReadPin)/5; //from 0 to 200 aprox. stringOne = potValue; stringTwo = stringOne + " "; lcd.print(stringTwo);} return potValue; } int getTimeLapse(void) { delay(500); lcd.clear(); lcd.setCursor(0,0); lcd.print("Use pot + Enter"); lcd.setCursor(0,1); lcd.print("T (mins): "); while(!digitalRead(buttonEnterPin)){ // select value until Enter lcd.setCursor(10,1); potValue = analogRead(potReadPin)/5; //from 0 to 200 aprox. stringOne = potValue; stringTwo = stringOne + " "; lcd.print(stringTwo);} return potValue; } // takes n pictures as defined in the variable shots void startTimeLapse(unsigned long shots, unsigned long interval) { showParameters(); while (shots) { stringOne = shots; stringTwo = stringOne + " "; lcd.setCursor(0,1); lcd.print(stringTwo); // prints remaining shots takePicture(); shots--; delay(interval-shutterDelay); } } void takePicture(void) { digitalWrite(shutterPin, HIGH); delay(shutterDelay); digitalWrite(shutterPin, LOW); }