number of rotations: servo motor

How to control the number of rotations of servo motor?

i want to fix on the number of rotations.

I am using putting a part of my code here:

 unsigned int keystate = 0;
  if (bs1 == HIGH) bitSet(keystate , 0);  // 1 - 1 (BIN)
  if (bs1a == HIGH) bitSet(keystate , 1);  // 2 - 10
  if (bs2 == HIGH) bitSet(keystate , 2);  // 4 - 100
  if (bs2a == HIGH) bitSet(keystate , 3);// 8- 1000
  delay(1000);

  Serial.print("STATE: "); 
  Serial.println(keystate, BIN);  // 0-15 = 0 - 1111
  
  temp= val;
  val = val1;
  val1 = temp;

  switch (keystate )
  {
  case 1: // bs1 pressed others not
      myservo1.write(val1);              // tell servo to go to position in variable 'pos' 
    delay(1500);                       // waits 15ms for the servo to reach the position 
    Serial.println("Ax");
   myservo1.detach();
     delay(1500); 
   break;

How to control the number of rotations of servo motor?

Is this another modded continuous rotation "servo" question?

delay(1500);                       // waits 15ms for the servo to reach the position

1500milliseconds is a second and a half.

i want to rotate the motor twice with one HIGH signal..here the servo rotates 180 degrees and back to 0 degrees.

A servo normally only rotates to 180 degrees or less.
It is physically and electrically limited to this range.

Are you saying you want it to do two cycles of 0 -> 180 -> 0 ?

here the servo rotates 180 degrees and back to 0 degrees.

I see no evidence for that in the code you posted.

ya i posted a part of the code.
actually i am not able to stop the motor at 180 degrees position.
as the conditions are fulfilled in the switch case it is reading HIGH and the rotation is not stopping.

You need to post your code.
This isn't making much sense.

You realise an ex-servo can't be commanded to a set position?
It can be told to rotate in one direction or another (possibly with a degree of speed control), or stop, but not turn to a specified angle, without the addition of external hardware.

ok here is my code

#include <Servo.h>

Servo myservo1;
Servo myservo2;
//Servo myservo3;

const int  buttonPin1 = 2;    // Axthe pin that the pushbutton is attached to
const int  buttonPin1a = 3;  //Bx
const int  buttonPin2 = 4;    //Ay
const int  buttonPin2a = 5;    //By
//const int  buttonPin3 = 6;    //Az
//const int  buttonPin3a =7 ;    //Bz

const int serPin1 = 9;       // the pin that the servo is attached to
const int serPin2 = 10; 
//const int serPin3 = 11; 

//int lbs1 = 0;     // previous state of the button
//int lbse2 = 0; 
//int lbs1a = 0;
//int lbs2a = 0; 

int bs1 = 0;         // current state of the button
int bs2 = 0;         // current state of the button
int bs2a = 0;  
int bs1a = 0;
//int bs3 = 0;  
//int bs3a = 0;

int val= 180;
int val1= 0;
int temp;
int pos=0;

void setup() {
  
  myservo1.attach(9);
  myservo2.attach(10);
//  myservo3.attach(11);
  // initialize the button pin as a input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin1a, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin2a, INPUT);
//  pinMode(buttonPin3, INPUT);
//  pinMode(buttonPin3a, INPUT);
//  // initialize the LED as an output:
  pinMode(serPin1, OUTPUT);
  pinMode(serPin2, OUTPUT);
//  pinMode(serPin3, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}
void loop()
{
  myservo1.attach(9);
  myservo2.attach(10);
//  myservo3.attach(11);
  
  digitalWrite(buttonPin1, HIGH);  // pull-up
  digitalWrite(buttonPin1a, HIGH);
  digitalWrite(buttonPin2, HIGH);
  digitalWrite(buttonPin2a, HIGH);
  
  bs1= digitalRead(buttonPin1);   // LOW = 0 HIGH = 1
  bs1a = digitalRead(buttonPin1a);
  bs2 = digitalRead(buttonPin2);
  bs2a = digitalRead(buttonPin2a);
  
//  bs3 = digitalRead(buttonPin3);
//  bs3a = digitalRead(buttonPin3a);

  unsigned int keystate = 0;
  if (bs1 == HIGH) bitSet(keystate , 0);  // 1 - 1 (BIN)
  if (bs1a == HIGH) bitSet(keystate , 1);  // 2 - 10
  if (bs2 == HIGH) bitSet(keystate , 2);  // 4 - 100
  if (bs2a == HIGH) bitSet(keystate , 3);// 8- 1000
//  if (bs3 == HIGH) bitSet(keystate , 4); // 16- 10000
//  if (bs3a == HIGH) bitSet(keystate , 5);// 32 - 100000
//  
  delay(1000);

  Serial.print("STATE: "); 
  Serial.println(keystate, BIN);  // 0-15 = 0 - 1111
  
  temp= val;
  val = val1;
  val1 = temp;

  switch (keystate )
  {
  case 1: // bs1 pressed others not
      myservo1.write(val1);              // tell servo to go to position in variable 'pos' 
    delay(1500);                       // waits for the servo to reach the position 
    Serial.println("Ax");
   myservo1.detach();
     delay(1500); 
   break;

  case 2: // bs1a pressed others not
    myservo1.write(val1);
    delay(1500);
    Serial.println("B-x");
    myservo1.detach();
    break;
    
  case 4 : // bs2 pressed others not
    myservo2.write(val1);
    delay(1000);
    Serial.println("Ay");
    myservo2.detach();
    break;

  case 8: // bs2a pressed others not
    myservo2.write(val1);
    delay(1000);
    Serial.println("B-y");
    myservo2.detach();
    break;

  case 5: // bs1 and bs2 pressed others not
    myservo1.write(val1);
    delay(1000);
    Serial.println("AA");
     myservo2.write(val1);
    delay(1000);
     myservo1.detach();
    break;
    
   case 10: // bs1 and bs2 pressed others not
    myservo1.detach();
    myservo2.detach();
    delay(1000);
    Serial.println("BB");
    break;
    
   case 9: // bs1-Ax and bs2a-By pressed others not
   Serial.println("AxBy");
    myservo2.write(val1);
    delay(1500);
    
//     myservo1.write(val1);
//    delay(1500);
    Serial.println("AxAy");
    myservo1.detach();
    myservo2.detach();
    break;
    
   case 6: // bs1a-Bx and bs2-Ay pressed others not
   Serial.println("BxAy");
    myservo1.write(val1);
    delay(1500);
    
//    myservo2.write(val1);
//    delay(1500);
    Serial.println("AxAy");
    myservo1.detach();
    myservo2.detach();
    break;

 case 0: // no keys pressed;
    break;

  default:  // invalid key combination
    // error message
    Serial.println("Invalid key combination pressed");
    break;
    
  myservo1.detach();
  myservo2.detach();
    
  }
}

here i want the servo to stop after 1 rotation until another case is called.

i want the servo to stop after 1 rotation until another case is called

I don't understand the last part of this sentence.
What do you mean by "another case is called"?

m1804:
here i want the servo to stop after 1 rotation until another case is called.

Did you read the post immediately before yours? Let me quote it for you.

You realise an ex-servo can't be commanded to a set position?
It can be told to rotate in one direction or another (possibly with a degree of speed control), or stop, but not turn to a specified angle, without the addition of external hardware.

So, a servo that has been modified to continuous rotation cannot be controlled in a way that will make it stop at a specific location.

When you state that you want the servo to stop after 1 rotation, you are describing a specific location.

I am going to shout now. YOU CANNOT DO THAT WITH THE HARDWARE YOU HAVE!

You will need to add an encoder to replace the position sensitive pot that was disabled/removed when the servo was modified for continuous rotation.