Wie Arduino Servos entgegengesetzt ansteuern?

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);
}

qwertzvsqwerty 
Fragesteller
 09.06.2016, 18:02

Fast! Der andere Servo soll sich ohne Poti drehen.

0
DorManu  10.06.2016, 15:24

Ohne Poti hab ich noch nie Probiert.
Sry das weis ich nicht.

0