Wie Arduino Servos entgegengesetzt ansteuern?
Hallo, wie kann man mit Arduino zwei Servos entgegengesetzt und gleichzeitig ansteuern? Hat jemand ein Beispielprogramm?
Vielen Dank schon einmal im Voraus!
1 Antwort
Ich weiß nicht ob du das meinst. Aber ich hab hier mal ein Beispiel gemacht.?
2 Servos (myservo1, myservo2)
myservo1 soll von Schritt 0 bis 50 "hochlaufen", dann wieder bis auf 0 "runterlaufen" und so weiter..
myservo2 soll mittels Poti gesteuert werden.
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int pos = 0;
int potpin = 0;
int val;
long previousMillis = 0;
long intervall = 100;
void setup()
{
myservo1.attach(9);
myservo2.attach(10);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > intervall){
previousMillis = currentMillis;
myservo1.write(pos);
pos=pos+1;
if(pos == 50){ // ab hier wird's knifflig ;-)
pos=pos-1; // ???
???
myservo1.write(pos);
}
}
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
myservo2.write(val);
}
Kein Problem, so ist es aber auch schon in Ordnung.
Fast! Der andere Servo soll sich ohne Poti drehen.
Ohne Poti hab ich noch nie Probiert.
Sry das weis ich nicht.