티스토리 뷰
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