#include <Servo.h> 

 /*서보모터 라이브러리를 사용하기위해 Include */

Servo myservo;  // create servo object to control a servo 

                // twelve servo objects can be created on most boards

 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 

/*실제로 제어할 서보의 제어핀의 번호*/

 

void loop() 

  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 

  {                                  // in steps of 1 degree 

    myservo.write(pos);              // tell servo to go to position in variable 'pos' 

    /* 서보모터에게 pos값의 각도로 이동하라는 명령.*/

      Serial.print(pos); 

Serial.print("\n");

/*시리얼모니터를 통한 pos 값 확인을 위한 소스*/

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

  } 

  /*왼쪽으로*/

  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 

  {                                

    myservo.write(pos);              // tell servo to go to position in variable 'pos' 

    Serial.print(pos);

     Serial.print("\n");

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

  } 

  /*오른쪽으로*/



Posted by 샌츠
,