Arduino控制360度旋转舵机



#include  
 
Servo myservo;  // create servo object to control a servo 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
   Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
   myservo.write(90);              
   delay(15);           
} 
 
 
void loop() 
{ 

  char ch = Serial.read();
  switch(ch){
      case 's': 
      {
        myservo.write(80);             
        delay(1000);                      
        Serial.println("N is inputed");
        myservo.write(90);             
        delay(1000);                     
        break;
      }
      case 'n':
      {
        myservo.write(100);             
        delay(1000);                       
        Serial.println("S is inputed");
        myservo.write(90);              
        delay(1000);                  
        break;
      }
  }     
} 

你可能感兴趣的:(Arduino控制360度旋转舵机)