Re: Controls for a project

Robin2:

techmodek:
yes robin2. your code has a few faults and you mustve read my mind.

Well I had to leave something to keep the cobwebs out of your brain :slight_smile:

I'm interested to hear what the shortcomings are.

I don't think it has any "faults" as compared to my specification for it, but I am well aware that my specification is much more limited than yours.

I believe it should be easy to extend its capabilities - I wrote it with that in mind.

...R

#include <Servo.h>

#define mainArm 0
#define jib 1
#define bucket 2
#define slew 3
#define left 4
#define right 5

Servo servo[6];

byte angle[6] = {90, 90, 90, 90, 90, 90};

byte potPin[6] = {A0, A1, A2, A3, A4, A5};
byte servoPin[6] = {12, 11, 10, 9, 8, 7};

void setup() {

Serial.begin(9600);
  Serial.println("Starting DiggerCode.ino");

for (byte n = 0; n < 6; n++) {
    servo[n].attach(servoPin[n]);
  }
}

void loop() {
  readPotentiometers();
  moveServos();
  delay(10);
}

void readPotentiometers() {
  int potVal;
  for (byte n = 0; n < 6; n++) {
    potVal = analogRead(potPin[n]);
   
    if (potVal < 450) {
      angle[n] += 1;
      if (angle[n] > 170) {
        angle[n] = 170;
      }
    }
   
    if (potVal > 570) {
      angle[n] -= 1;
      if (angle[n] < 10) {
        angle[n] = 10;
      }
    }

}
}

void moveServos() {
  for (byte n = 0; n < 6; n++) {
    servo[n].write(angle[n]);
  }
}