티스토리 뷰

카테고리 없음

Attiny13으로 PWM 제어하기

파란만두 2018. 10. 14. 10:16
Servo control with Attiny13 byte servoPin=0; void setup() { pinMode(servoPin, OUTPUT); PulseOut(servoPin, 0); Delay (1000); PulseOut(servoPin, 90); Delay (1000); PulseOut(servoPin, 180); Delay (1000); PulseOut(servoPin, 0); } void loop() { /* for (byte pos=0;pos<180;pos++) { pulseOut(servoPin, pos); delay(20); } */ } void pulseOut( byte pin, byte p){ digitalWrite(pin,HIGH); delayMicroseconds(1000+p*(1000/180)); digitalWrite(pin,LOW); delayMicroseconds(20000-1000+p*(1000/180)); } 출처: https://arduinodiy.wordpress.com/2015/05/20/servo-on-attiny13/ PWM at PB0 and 1: https://www.siklosi.com/en/attiny13-pwm-candle/ 또다른 예: welcome. // **** ATtiny Servo Sweep Example **** // const byte servo = 0; // Servo pin on ATtiny int tPulse = 4000; // Total pulse length on 1 Mhz clock int hPulse = 60; // High pulse time (60=0deg -> 280=180deg) bool Dir = 1; // Servo direction void setup() { pinMode(servo, OUTPUT); } void loop() { digitalWrite(servo, HIGH); // Set pin high to start pulse delayMicroseconds(hPulse); // High pulse angle data digitalWrite(servo,LOW); // Set low for the rest of pulse delayMicroseconds(tPulse-hPulse); if (hPulse < 280 && Dir == 1) hPulse+=10; // Rotate servo to 180 degrees else if (hPulse >= 280 && Dir == 1){ // Servo hit upper limit hPulse = 280; // Keep servo angle in bounds Dir=!Dir; // Switch direction } if (hPulse > 60 && Dir == 0) hPulse-=10; // Rotate servo to 0 degrees else if (hPulse <= 60 && Dir == 0){ // Servo hit lower limit hPulse = 60; // Keep servo angle in bounds Dir=!Dir; // switch direction } delayMicroseconds(500); // Give servo some time to move before giving it a new position } https://www.youtube.com/watch?v=Dt-z27TL_Hg?hl=en_US 출처: https://www.robotshop.com/community/forum/t/attiny-servo-control/4088
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함