Servo myservo;
int pos = 0;
void setup()
{
myservo.attach(9);
}
void loop() {
incomingByte = Serial.read();
while ( incomingByte == 97 && Serial.available () == 0) //left aileron
{
myservo.write(45);
}
while ( incomingByte == 100 && Serial.available () == 0) //right aileron
{
myservo.write(135);
}
while ( incomingByte == 119 && Serial.available () == 0) //pitch down
{
myservo.write(45);
}
}
alright, i understand this program sends a 45 degree to the servo, and i believe the servo is output pin 1. how should i modify this program, or maybe the variables, to allow me to control more ch at the same time instead of 1. in this case, as from the program above, my third one is to control pitch, which is ch 2, but i cant get ch 2 moving, no matter what chat i type, ch 1 will move. is it due to the declaring of myservo.attach(9)?
if yes, how to i modify it?
1 more question:
what is the code that sends the signal to the brushless motor to allow the motor to rotate? like for the servo case, its myservo.write..
thanks..
darren
You need to be a member of diydrones to add comments!
Replies
#include servo.h
// brackets required around servo.h.
Servo myservo1 // create first servo object
Servo myservo2 // create second servo object
myservo1.attach(9); // attaches the servo on pin 9 to the first servo object
myservo2.attach(10); // attaches the servo on pin 10 to the second servo object
// I believe pins 3, 5, 6, 9, 10, and 11 are the PWM pins required for servo output on a standard Arduino.
myservo1.write(45); // will turn the servo to 45 degrees. 0-180 degree range.
myservo2.writeMicroseconds(1500); // alternate usage in microseconds.
// 1000 is fully counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle for servos.
// use this for the brushless motor ESC. It is a type of servo, controlling rpms instead of angle.