Hi all. I am new to arduino, and thought that for my first project, I would tackle the ever-popular camera intervalometer.

I have a decent understanding of the circuit I would like to use, aside from how I will minimize the number of necessary input ports on the arduino. I have an idea as to how things will work, but I would appreciate a little guidance on how I handle button presses.

UPDATE: See 3rd reply for slight update

I have 4 input buttons (Left, Right, Up, Down) and they will cause my lcd to refresh and increase my various values, etc. My initial idea was something like:

if (stateR==HIGH){do something;} if (stateL==HIGH){do something;} if (stateU==HIGH){do something;} if (stateD==HIGH){do something;}// is a bit double so my advice is to skip the middle boolean// allso when using a if in comination with a boolean you dont need the ==HIGH// so a sample line will be

if(digitalRead(BTN_x)){doobiedo;}

// we can even clean this up some more because when there is not more then 1 action after a statement there is no need for { }if(digitalRead(BTN_x))doobiedo;

obviousely this is not at all a awnser to youre question, but i am not entirly sure what the question iswill give you a very important tipin your code you use ""if (stateR==HIGH)"" this will cause some serious bugs because when you press the button the action after the if statement will be executed a couple of times so ther will be far more the one meassurement done. try researching how to prgram a switch to execute a action on the uprising or falling flank. if you dont understand this i will explain it a little better

Does this make sense? I will look more into the "uprising flank" mentioned.

You may have an issue finding information with that term, as I've never seen it called that before. The more commonly used term would be signal edge detection. Basically, you want the instant that the signal changes from HIGH to LOW (Falling edge) or LOW to HIGH (Rising Edge). There are plenty of libraries dealing with this for buttons, but it's pretty simple to implement in Arduino.

You simply need to keep track of the last reading of the button, and compare it with the current reading. If they are different, then a signal edge was detected. Here is a quick example:

I did understand what he meant, I dealt with it a little when I coded in labview. But you are correct, and I did not know the proper term. I was thinking more along the lines of the button, ie. latched, etc.

Thanks, I may need to add that functionality into my code when it progresses.

---explanation why to use the rising edge/uprising flank---when you use tact switches (switches where contact is made when pushed and lost when released) or any kind of singlepole toggle switch there is a problem you should watch out for. because you hold the switch at very least for 40-100 ms(random guess) and your program's looptime is much less. Your program will register the button you pushed only once, as if it was pushed many times in a row. this will result in that the action you wanted to link to the button will be executed many times. one of the solutions is to program your arduino so that the button will only be registerd as pushed when the in previous loop it wasn't pushed. thus when the INPUT rises from '0' to '1'. <--thats the rising flank for ya

Also i'm still not quite sure what the question is you were asking?!

and ofcourse a litle tip to close the deal:i think this is much more logical (and probably faster) it also removes a neatness bug that when 2 opposite buttons are pushed the screen goes back and forth rapidly

Thanks Daatse,I was able to get some response from my buttons with my initial code, though I did have the problem of dealing with one button press being registered as many as you described. My question was "Am I dealing with button presses in a proper and efficient way". It has now become clear that I was not.

I think you are making a good point bringing up the latched issue (you call it flanking). I think I need to incorporate that into my code. Shall I look for a library, or function to use? Perhaps I will make one. I do not know if this will change things, but I may want to use a rotary encoder rather than buttons in my final design, will that still present the latching/flanking issue?

Also, is it a problem to refresh the screen that many times? At the moment I am using the 16x2 LCD, but I may move to a few alphanumeric segmented displays.

int currentReading = digitalRead(i); // only use this when using pin 1 to 4 when using for example pin9 to 13 use digitalRead((i+9));if ((status[i]==LOW)&&(currentReading==HIGH)) {//the behavior that that switch schould provoke}status[i] == currentReading;}}

something like the above, the above code is only to help you it will probably not work

also that much refreshes are not really a problem but when holding 2 buttons it will rapidly show oneframe and then a other (much like nowadays videoclips)

I will definitely use more arrays in my code now. I was previously defining my menu by leaving the titles in a string array (ie. {"exposure","interval","iterations"}) and then stepping through the array when a keypress was registered. The ideas you both mentioned will be a nice addition.

Thanks, I think I have enough to go test out some different algorithms. I will report back if i hit any problems.

Well I made some progress. I do have a loop but I am just going to show one button press to keep it simple. I am using the following code, but it still seems "laggy" or non-responsive with some presses. Many work fine but far from all. Does anyone have an opinion or explanation?