hello alltogether,
I'm bloody new to arduino & co, unfortunately lost and might need some help
with synchronising some servos.
Just shortly to understand my project:
I want to create a movable "water-tap" controlled by 3 servos.
See:
http://www.freshform.de/download/Mario.movTo get some kind of realistic behaviour/gestures, the servos need to
work all simultaneously! So I could e.g. create a circular movement out of
back/forth and left/right.
With my code so far, the functions only go one after the other, which defentitely
doesn't work for my purpose.
//int pulse = 0; // Amount to pulse the servo
//int end = 0;
//int act =0;
//int counter=0;
/*int refreshTime = 20; // the time needed in between pulses
unsigned long lastPulse = 0;*/
//int analogValue = 0; // the value returned from the analog sensor
//int analogPin = 0; // the analog pin that the sensor's on
// minPulse = links ; maxPulse = rechts
//servo1
int servoPin1 = 2; // Control pin for servo motor
int minPulse1 = 850; // Minimum servo position
int maxPulse1 = 1400; // Maximum servo position
//servo2
int servoPin2 = 3; // Control pin for servo motor
int minPulse2 = 500; // Minimum servo position
int maxPulse2 = 2400; // Maximum servo position
//servo3
int servoPin3 = 4; // Control pin for servo motor
int minPulse3 = 400; // Minimum servo position
int maxPulse3 = 2400; // Maximum servo position
void setup() {
pinMode(servoPin1, OUTPUT); // Set servo pin as an output pin
pinMode(servoPin2, OUTPUT); // Set servo pin as an output pin
// pinMode(potPin, INPUT); // Set servo pin as an output pin
//pulse = 1500; // Set the motor position value to the minimum
Serial.begin(9600);
}
void loop() {
moveServo(servoPin1, 850, 1400,1,1,2,2);
moveServo(servoPin2, 500, 2400,3,3,5,5);
}
void moveServo(int servoPin, int minPulse, int maxPulse, int v1, int v2, int d1, int d2) {
for (int i=minPulse; i<maxPulse; i = i + v1) {
// count up
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(i); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(d1);
}
for (int i=maxPulse; i>minPulse; i = i - v2) {
// count down
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(i); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(d2);
}
}
/*
void moveServo1() {
for (int i=minPulse; i<maxPulse; i = i + 1) {
// count up
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(i); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(2);
}
for (int i=maxPulse; i>minPulse; i = i - 1) {
// count down
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(i); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(2);
}
}
}*/
/*
void moveServo2() {
for (int i=minPulse; i<maxPulse; i = i + 3) {
// count up
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(i); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(5);
}
for (int i=maxPulse; i>minPulse; i = i - 3) {
// count down
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(i); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(5);
}
}*/
Does anyone has an idea, understandable for a beginner like me?
tx for all thinking
joto