原始碼如下:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup()
{
Serial.begin(9600);
myservo.attach(9);
}
int pulse =2450;
int dir=1;
int offset=1;
void loop()
{
myservo.writeMicroseconds( pulse );
if ( pulse + offset >= 2450 ) dir = -1;
else if ( pulse - offset <= 600 ) dir = 1;
pulse += ( offset * dir);
Serial.println ( pulse, DEC );
}
沒有留言:
張貼留言