#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
}
/*오른쪽으로*/
}
'아두이노' 카테고리의 다른 글
가변저항으로 LED 밝기 조절하기. (0) | 2017.06.09 |
---|---|
[스크랩][아두이노 강좌] 14. 아두이노로 서보모터 제어하기 (0) | 2017.01.17 |
[스크랩][아두이노 강좌] 07. 버튼을 이용하여 RGB LED 색상 제어하기 (0) | 2017.01.17 |
[스크랩][아두이노 강좌] 06. 푸쉬버튼을 이용한 디지털 입력하기 (0) | 2017.01.17 |
[스크랩]아두이노 디지털 핀에 24V 입력받기(저항으로 전압강하, 전압분배) (0) | 2017.01.12 |