一个arduinof的程序问题
#include <Servo.h>Servo myservo;// create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9);// attaches the servo on pin 9 to the servo object
pinMode(2,INPUT);
pinMode(3,INPUT);
}
void loop()
{
int val1;
int val0;
val0=digitalRead(2);
val1=digitalRead(3);
if(val0==0)
{
for(pos = 0; pos < 160; 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'
delay(15); // waits 15ms for the servo to reach the position
}
}
if(val1==0)
{
for(pos =180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
为什么无论2,3脚接vcc还是地,舵机都一直在转? 弱弱的问一下,为什么一个是160,一个是180啊? zhanggang1971 发表于 2012-1-25 19:48 static/image/common/back.gif
弱弱的问一下,为什么一个是160,一个是180啊?
饿,这个是瞎写的 motor和arduino共地么?
页:
[1]