I make it to work as i want.Here is my code:
#include <Servo.h>
//#define mainArm 0
//#define jib 1
//#define bucket 2
//#define slew 3
Servo servo[4];
int angle[4] = {100, 100, 100, 1472};
byte potPin[4] = {A0, A1, A2, A3};
byte servoPin[4] = {12, 11, 10, 9};
void setup() {
Serial.begin(9600);
Serial.println("Starting DiggerCode.ino");
for (byte n = 0; n < 4; n++) {
servo[n].attach(servoPin[n]);
servo[n].writeMicroseconds(angle[n]);
}
}
void loop() {
readPotentiometers();
moveServos();
delay(10);
}
void readPotentiometers() {
int potVal;
int button = 1;
for (byte n = 0; n < 4; n++) {
potVal = analogRead(potPin[n]);
potVal = map(potVal, 0, 1023, 544, 2400);
if ( button == 1){
if (potVal > 1572) {
angle[n] += 10;
if (angle[n] > 2399) {
angle[n] = 2400;
}
}
if (potVal < 1372) {
angle[n] -= 10;
if (angle[n] < 545) {
angle[n] = 544;
}
}
if (potVal < 1372 && angle[n] > 1572){ //kick off code
angle[n] = 1472;
delay(20);
}
}
else if (potVal >= 1372 && potVal <= 1572 ) {
angle[n] = 1472;
}
else if (potVal <= 1372 ) {
angle[n] = potVal + 100;
}
else if (potVal >= 1572 ) {
angle[n] = potVal - 100;
}
}
}
void moveServos() {
for (byte n = 0; n < 4; n++) {
servo[n].writeMicroseconds(angle[n]);
}
}
Now im struggling with "kick off" code. it works , but not smooth as i want. Any suggestion about this?