Photobooth

Hi,

I have some trouble with a part of my code witch is suppose to keep my camera active instead of gooing on sleep after 15 minutes. My code for the “main project” works fine… After my button being pushed, my camera takes 3 shoots. The problem is that if nobody push the damn button for 15 minutes, my camdera goes on standby.

Here is some part of my code witch did’nt work…

long LastPic;
long interval;
Void setup(){
LastPic = millis();
}
void loop(){
interval = millis()-LastPic;
if ( blablabla){ "part that goes great"
LastPic= millis();
}
if (interval >= 5000){
"here I'm taking a picture";
LastPic = millis();
}
}

You can go and check my full code in the attatched file

photobooth_V2.0.ino (5.73 KB)

OP’s actual code instead of whatever that was that he posted inline…

#include <multiCameraIrControl.h>

Nikon D5000(11);

const int buttonPin = 10;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status
int pause = 500;            // Valeur d'attente...
int pause2 = 1000;          // Valeur d'attente x 2
long LastPic;
long interval;

void countd5(){
 //// write '5'
 digitalWrite(2, 1);
 digitalWrite(3, 0);
 digitalWrite(4, 1);
 digitalWrite(5, 1);
 digitalWrite(6, 0);
 digitalWrite(7, 1);
 digitalWrite(8, 1);
 delay(pause2);
 //// write '4'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 1);
 digitalWrite(8, 1);
 delay(pause2);
 //// write '3'
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 1);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
 delay(pause2);
 //// write '2'
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
 delay(pause2);
 //// write '1'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
 delay(pause2);
//// write -
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
}

void countd3(){
//// write '3'
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 1);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
 delay(pause);
 //// write '2'
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
 delay(pause);
 //// write '1'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
 delay(pause);
//// write -
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
}


//-----------------------------------------------------
void setup(){

  pinMode(buttonPin, INPUT);
  // pin for SSD
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(9, 0);  // start with the "dot" off } unsigned long AutoShootTimer;
}

void loop(){

interval = millis() - LastPic;
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
  // ********** photo #1
countd5();
    D5000.shutterNow();
  delay(pause2);
  // ********** photo #2
countd3();
    D5000.shutterNow();
   delay(pause2);   
  // *********** photo #3
countd3();
  D5000.shutterNow();
   delay(pause2);
 // Write " "
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
   LastPic = millis();    
  }

if (interval >= 5000){
  D5000.shutterNow();
}
  
}
long LastPic;

should be unsigned long so the time can’t roll over to negative numbers.

By the way, go study how this works. It will save you a lot of typing on your countdown code and if you ever want to display anything else to the 7 segment.

byte digits[] = {0b1111110 , 0b0110000, 0b1101101, 0b1111001, 0b0110011, 0b1011011, 0b1011111, 0b1110000, 0b1111111, 0b1111011};

// pins to segments g,f,e,d,c,b,a
byte pins[] = {3,4,5,6,7,8,9};

void displayNumber(int aNumber) {  
  for (int i = 0; i < 7; i++) {
    digitalWrite(pins[i], digits[aNumber] & (1 << i));
  }
}

void setup(){
  for (int i = 0; i < 7; i++){
    pinMode(pins[i], OUTPUT);
  }
}


void loop(){
   // Count up 0 to 9
  for (int i = 0; i < 10; i++) {
    displayNumber(i);
    delay(1000);
  }
}
if (interval >= 5000){
  D5000.shutterNow();
}

This bit is missing a critical piece that you actually included when you "rewrote" the code into nonsense in the first post.

I suspect your code is far away more complex than needed.
please give to your outputs a names it will be more easy for people to understand.

I know that I’m very far from beeing good at coding but i’m getting married in 2 weeks and that last part (the one where my camera goes standby) is important for the good working of my photobooth!

I’ll be working on my programmer skils right after my wedding

Tibi_qc:
I’ll be working on my programmer skils right after my wedding

How's that going to help you get it working before the wedding?

You've been given two suggestions for things to fix and one suggestion to make your code easier to read to make it easier for someone to try to help you. If you're not going to address either of those things then we seem to be at an impasse. Please come back when you're ready to address those.

Ok then, forget my first post... :wink:

I add a while loop into my main loop. I wanted it to check if my button is pushed. If not, then wait for 15 sec and take a picture. Instead of dooing it, once my while loop is add to my existing code, nothing happen...

while (digitalRead(buttonPin) == LOW){
  delay(15000);
  D5000.shutterNow();
  delay(50);
}

I guess it depends on where in your code you put that.

It's inserted after my if loop (in my main loop)...

You're not using the internal pull-ups and you're expecting the button to read backwards. You want it to be HIGH when pressed instead of LOW.

So I have to ask, do you have an external pull-down on that button pin? Would be much easier to use the internal pull-up resistors and have the button read LOW when it is pressed like the normal way.

Tibi_qc:
It's inserted after my if loop (in my main loop)...

There's no such thing as an "if loop". if is a statement, they don't loop.

Either way, posting the actual new code there would be a lot more useful than just a description of where you put it don't you think? I mean I don't care but you are the one who said you were on a time table. So thinking about these sorts of things and not having to be asked every time would probably help you get there a lot faster.

while (digitalRead(buttonPin) == LOW){
  delay(15000);
  D5000.shutterNow();
  delay(50);
}

What happens if someone shows up and wants their picture taken during that 15 second wait? They'd have to press the button at just the right millisecond to get it read when it gets back around to that digitalRead or they'd have to hold the button down for 15 seconds while they wait for that delay to end.