48 lines
978 B
C++
48 lines
978 B
C++
|
|
#include <Servo.h>
|
|
|
|
Servo myservo1; // create servo object to control a servo
|
|
Servo myservo2; // create servo object to control a servo
|
|
Servo myservo3; // create servo object to control a servo
|
|
|
|
int value; // variable to read the value from the analog pin
|
|
|
|
void setup()
|
|
{
|
|
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
|
|
myservo3.attach(10); // attaches the servo on pin 9 to the servo object
|
|
myservo3.attach(11); // attaches the servo on pin 9 to the servo object
|
|
|
|
Serial.begin(9600);
|
|
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
|
|
if (Serial.available()) {
|
|
|
|
value = Serial.read();
|
|
if(value == 201)
|
|
{
|
|
delay(5);
|
|
myservo1.write(Serial.read());
|
|
}
|
|
else if(value == 202)
|
|
{
|
|
delay(5);
|
|
myservo2.write(Serial.read());
|
|
}
|
|
else if(value == 203)
|
|
{
|
|
delay(5);
|
|
myservo3.write(Serial.read());
|
|
}
|
|
|
|
}
|
|
|
|
delay(15); // waits for the servo to get there
|
|
|
|
}
|
|
|