Ich will ja,dass das Programm nur einmal Ausgeführt wird.
Ich will ja,dass das Programm nur einmal Ausgeführt wird.
Geändert von Andri (19.12.2013 um 18:50 Uhr)
Kann man das in die Loop Schleife packen,ohne dass der Servo ständig hin und her dreht? Also sich nur einmal dreht,die Position hält und dann der nächste Ablauf kommt.
Ich habs mal so Ausprobiert,hat aber nicht geklappt:
//*Sweep
//*by*BARRAGAN*<http://barraganstudio.com>*
//*This*example*code*is*in*the*public*domain.
#include*<Servo.h>
*
Servo myservo; // create servo object to control a servo
****************// a maximum of eight servo objects can be created
*
int pos = 0; // variable to store the servo position
*
void setup()
{*
**myservo.attach(5); // attaches the servo on pin 9 to the servo object
**myservo.attach(4); // attaches the servo on pin 9 to the servo object
}*
*
*
*
void loop()
{*
**for(pos = 0; pos < 80; pos += 1) // goes from 0 degrees to 180 degrees
**{**********************************// in steps of 1 degree
****myservo.write(pos); // tell servo to go to position in variable 'pos'
****delay(15); // waits 15ms for the servo to reach the position
**}*
**
**for(pos = 0; pos < 70; pos += 1) // goes from 0 degrees to 180 degrees
**{**********************************// in steps of 1 degree
****myservo.write(pos); // tell servo to go to position in variable 'pos'
****delay(15); // waits 15ms for the servo to reach the position
**}*
}*
Das größte Problem, dass ich bei deinem Source-Code sehe, ist, dass du nur ein Servo-Objekt für 4 Servos erstellst.
Vorschlag:
Wenn du tatsächlich nur einmal den Bewegungsablauf ausführen willst, ist es ok die Befehle ins setup zu schreiben und die loop leer zu lassen.Code:#include<Servo.h> // 4 Servos Servo servo1; Servo servo2; Servo servo3; Servo servo4; // Positionen der 4 Servos int posServo1 = 0; int posServo2 = 0; int posServo3 = 0; int posServo4 = 0; void setup() { // Servos den Pins zuweisen servo1.attach(2); servo2.attach(3); servo3.attach(4); servo4.attach(5); // Bewegungen for(posServo4 = 0; posServo4 < 500; posServo4++) { servo4.write(posServo4); delay(15); } for(posServo3 = 0; posServo3 < 500; posServo3++) { servo3.write(posServo3); delay(15); } for(posServo2 = 0; posServo2 < 500; posServo2++) { servo2.write(posServo2); delay(15); } for(posServo1 = 0; posServo1 < 500; posServo1++) { servo1.write(posServo1); delay(15); } } void loop() {}
Allerdings soll das Programm später bestimmt auf irgendwelche Eingaben reagieren, dann muss das in die loop.
Die vier Variablen für die Positionen kann man später so nutzen:
Code:// weitere Bewegung: Servo4 zurück auf '250' for(; posServo4 > 250; posServo4--) { servo4.write(posServo4); delay(15); }
Geändert von Sisor (13.01.2014 um 22:20 Uhr)
Lesezeichen