Hi,
ich habe mal eine Frage. Es gibt ja bei Arduino das Beispiel für die
Servo Ansteuerung.
Jetzt habe ich das Beispiel schon mal erweitert, das es für zwei Motoren
sein soll.
Die Daten für den Servo sollen seriell hinein kommen.
Wie schreibe ich das aber bei Arduino?
Ich bin total neu in Arduino und hab leider noch überhaupt keine
Erfahrungen.
Der Code sieht erstmal folgendermaßen aus:
#include <Servo.h>
Servo myservo_links; // create servo object to control a servo
// a maximum of eight servo objects can be created
Servo myservo_rechts;
int pos_links = 0; // variable to store the servo position
int pos_rechts = 0;
void setup()
{
myservo_links.attach(9); // attaches the servo on pin 9 to the servo object
myservo_rechts.attach(10);
}
void loop()
{
///////////////////////////////
//Eingabe muss erfolgen
//
//////////////////////////////
// linker Servo:
for(pos_links = 0; pos_links < 180; pos_links += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo_links.write(pos_links); // tell servo to go to position in variable 'pos_links'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos_links = 180; pos_links >= 1; pos_links-=1) // goes from 180 degrees to 0 degrees
{
myservo_links.write(pos_links); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
// rechter Servo:
for(pos_rechts = 0; pos_rechts < 180; pos_rechts += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo_rechts.write(pos_rechts); // tell servo to go to position in variable 'pos_rechts'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos_rechts = 180; pos_rechts >= 1; pos_rechts -= 1) // goes from 180 degrees to 0 degrees
{
myservo_rechts.write(pos_rechts); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}