Hi all,
I had the same problem, thanks for the code, It really works!! ![]()
@Robin2 or anyone really. I would like that when i press a push button, the servo motors default a particular angle (maybe 0 degrees)
Below is the code I tried to accomplished this. My push-button is attached to dig pin 2 and i tired inserting the reading of pin 2 is high then set the potvalue to 512 which should be zero. But this didnt seem to work. Could someone assist me to accomplish this. Much thanks
#include <Servo.h>
#define mainArm 0
#define jib 1
#define bucket 2
#define slew 3
Servo servo[4];Â Â Â //code used for attaching upto 4 servos
byte angle[4] = {90, 90, 90, 90};Â Â Â // middle point for servo angle
byte potPin[4] = {A0, A1, A2, A3};Â // input pins to attach your potentiometers
byte servoPin[4] = {7, 6, 10, 9};Â Â // input pins to attach servos
const int buttonPin = 2 ; //Â Â Â Â Â Â Â push-button attached to 2
int buttonState = 0 ;Â Â Â //Â State of the push-button
int potVal ;
void setup() {
 Serial.begin(9600);
 Serial.println("Starting DiggerCode.ino");
 pinMode(buttonPin, INPUT) ;     // set push button as an input
 for (byte n = 0; n < 4; n++) {
  servo[n].attach(servoPin[n]);
 }
}
void loop() {
 readPotentiometers();
 moveServos();
 delay(10);
 buttonState = digitalRead(buttonPin);
 if(buttonState == HIGH);
 {
  potVal == 512;}
}
void readPotentiometers() {
 int potVal;
 for (byte n = 0; n < 4; n++) {
  potVal = analogRead(potPin[n]);
 Â
  if (potVal < 200) {    // dead zone for the joystick I used is 200 to 550.
   angle[n] += 1;
   if (angle[n] > 170) {
    angle[n] = 170;
   }
  }
 Â
  if (potVal > 550) {    // deadzone upper value
   angle[n] -= 1;
   if (angle[n] < 10) {
    angle[n] = 10;
   }
  }
 }
}
void moveServos() {
 for (byte n = 0; n < 4; n++) {
  servo[n].write(angle[n]);
 }
}