Servo motor stop loop code after pushbutton

Hi all,

I need to stop arduino loop code and save servo to default position in pusbutton linked to digital pin 5 and want to stay at this position until resetting arduino uno.What changes i must made with my code?
Here is my diagram;

1-Start(Done)
2-Read pot value from A1 and go position(Done)
3-Move servo(Done)
4-When pushbutton 4 pressed servo position goes default value 89 degrees(Done)
5-Relase pushbutton 4 came to where pot. value is(Done)
6-Push 5 th pin pushbutton stop arduino loop and go default value 89 degrees(here is the part i m asking for help)
7-Dont do anything until arduino reset or plug out-plug-in.(here is the part i m asking for help)

Here is my code:

#include <Servo.h>  
const int pot=A1; 
Servo myservo;  
int potdurum=0;     
int pos = 0;       
int basla=4;
int val;

void setup(){
  myservo.attach(9); 
  pinMode(basla, INPUT);
  digitalWrite(basla, HIGH);
} 
void loop()
{
  potdurum=analogRead(pot);
  pos= map(potdurum,0,1000,45,90);
  { 
    myservo.write(pos);
  }
  
  
 val=digitalRead(basla);  
 
   if(val!=1) 
    {
       myservo.write(89); 
       delay(15);         
    }

  
}

Thanks in advance.
Btw sorry for my poor english.

Best regards.

I presume you mean a second button attached to pin 5 (rather than 5 buttons).

I guess I don't really understand what the new button should do that is not already happening?

At the moment it goes to 89deg when you hold the button down. Otherwise it goes to the position set by the pot.

Do you want it to stay at 89deg if you press the second button?

A simple, if crude, way to do that would be like this

if (digitalRead(5) == LOW) {      // assumes you are using internal PULLUP resistors
   myServo.write(89);
   while(1);          // it will stay doing this forever
}

...R

Hi thanks for your reply

Yes i mean second button attached to pin 5

I want to second button push release will make servo to go 89 degrees and disable first button and potantiometer inputs until reset or plugged out plugged in.

“At the moment it goes to 89deg when you hold the button down. Otherwise it goes to the position set by the pot.” seems ok to me for first button.There is no problem.

I want it to stay at 89deg if i press and relase the second button until reset or replug arduino.

here is my new code is that right?:

#include <Servo.h>  
const int pot=A1; 
Servo myservo;  
int potdurum=0;     
int pos = 0;       
int basla=4;
int test=5;
int val;

void setup(){
  myservo.attach(9); 
  pinMode(basla, INPUT);
  digitalWrite(basla, HIGH);
} 
void loop()
{
  potdurum=analogRead(pot);
  pos= map(potdurum,0,1000,45,90);
  { 
    myservo.write(pos);
  }
  
  
 val=digitalRead(basla);  
 
   if(val!=1) 
    {
       myservo.write(89); 
       delay(15);         
    }
if (digitalRead(test) == LOW) {      // assumes you are using internal PULLUP resistors
   myservo.write(89);
   while(1);          // it will stay doing this forever
}
  
}

Best regards.

kelleci: here is my new code is that right?:

I presume that, by now, you have tried it out so you know what happens. If it does not work as you want let us know.

The Arduino system is great for learning-by-doing

...R

I was at work.I tried it at home and voila! thank you very very very much!!! Best regards.