#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(90);
delay(15);
}
void loop()
{
char ch = Serial.read();
switch(ch){
case 's':
{
myservo.write(80);
delay(1000);
Serial.println("N is inputed");
myservo.write(90);
delay(1000);
break;
}
case 'n':
{
myservo.write(100);
delay(1000);
Serial.println("S is inputed");
myservo.write(90);
delay(1000);
break;
}
}
}
版权声明:本文为zn845639326原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。