Electronics > Microcontrollers

Pausing a Arduino shetch, and wait for a button press

(1/3) > >>

Cj1corbystarlet:
Hi guy's,

I'm writing a sketch for a arduino to measure some time/input's per min, but i have to pause the sketch so the user can get things ready, then hit the button, complete the task then hit the button again to go onto the next task and so on ....

Can anyone give me some hints how this is done as i cant find any tutorials in the net for this.

Theoretically it should be easy as pie...... but i cant seem to do it.

I'm a wire monkey, not a coder

Ben
 

PeterG:
The easy way would be to use an interrupt on the input pin.

Regards

sub:
Try something to the effect of while(digitalRead(pin) == 0) {}, assuming you are pulling the pin high on a button press.

Cj1corbystarlet:
Ok i tried this and it works .... Sort of.

"
void loop()
{
 
{
  while (digitalRead(6)==0)
  {
    delay(10);                        //  debounce
  }
}
and the rest of the loop code works..        "

So yes, on powerup it processes my void Setup ()
loads my splash screen
Waits for a push of button 6 -- Yeah :)
then processes one run of the code, obviously goes back to the start of Void Loop()
and then waits for "the button push again.

I obviously need the void Loop() to continue to loop.....

Can i have a loop in a loop ? is "Goto" an option

Any ideas ?  My Basic and Turbo Pascal, and C  Programming days  are long gone (16 Years ago)

sub:
The "loop" there is just a function name.  You'll be wanting a while or for loop.  Avoid goto unless you really know what you are doing (e.g. for Linux-style cleanup).

It might be worth flicking through a C tutorial---once you have a grip on what constructs are available to you, you will be able to make things far more concise and manageable.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod