Understanding a "mode"-type structure

Hello there community!

Currently i am working on a project with buttons and a servo.

I want the circuit to let the user control the servo, and if needed, store the actual position of the servo.

I managed to get the circuit working flawlessly.

But now i am curious:

I am working with the Buttonlibrary and have a "record" button and some "slot" buttons.

Currently i am checking whether the "record" button is held down, and if another slot button is held down simultaneously.

I want to implement a "record mode", so that i press the record button, then a LED goes on, and nothing happens until one of the slot buttons is pressed, the variable is stored, and it exits the "record mode"

I dont have any clue how to do this, as the void loop() is running through and through and i cant stop it until something happens.

Thanks for a possible head-up

Greetings

apogee

When the "record" button is pressed, call a function that loops, checking the state of the "slot" buttons, until the state of one of the "slot" buttons changes to pressed.

Thanks for the answer, Paul!

Totally simple at the first glance.

How can i exit the "void checkbuttons();" if a button ist pressed and go back to the void loop(); ? I searched the Arduino-Reference, but i cant find anything like "exit".

Or am i getting something totally wrong here?

You can return from a function by using the return keyword.

void checkButtons()
{
   for(;;)
   {
      if(digitalRead(slotBtn1) == HIGH)
         return;
      if(digitalRead(slotBtn2) == HIGH)
         return;
   }
}

If you care which button was pressed:

int checkButtons()
{
   for(;;)
   {
      if(digitalRead(slotBtn1) == HIGH)
         return 1;
      if(digitalRead(slotBtn2) == HIGH)
         return 2;
   }
}

(Or return slotBtn1 or slotBtn2...)

Now thats a precise and useful answer!

Many thanks for the good tips, Paul.

As soon as i come back from work, ill write my code.

Greetings,

apogee