Timer1 - 서보모터

BABY CAT·2023년 7월 17일
0

Arduino

목록 보기
11/28

서보모터

서보모터는 0도~180도로 제어가 가능하지만

오차를 줄이기 위해 실제로는 10도~170정도로 움직인다

타이머를 활용한 서보모터 제어


#include <TimerOne.h>



const int Servo = 10;

const int Servo_Period = 20000;

const int Servo_Minduty = (1024/20)*0.7; //=35  서보모터0도

const int Servo_Maxduty = (1024/20)*2.3; //=117  서보모터180도



void setup(){

 Timer1.initialize();

 Timer1.pwm(Servo,0);

 Timer1.setPeriod(Servo_Period);

}



void loop() {

 // put your main code here, to run repeatedly:

 for(int angle=Servo_Minduty; angle<=Servo_Maxduty; angle++){

  Timer1.setPwmDuty(Servo,angle);

  delay(30);

 }

}

0도부터 180도 까지 점차 변하는 것을 무한반복

1개의 댓글

comment-user-thumbnail
2023년 7월 18일

항상 좋은 글 감사합니다.

답글 달기