Hi, I have set-up a 5 dof robotic arm with my arduino. I want it so that I can control all the servos individually with one potentiometer. I have 5 leds to indicate which servo I am controlling and 3 buttons one left to scroll left and one right to scroll right and a third button to tell the ardunio when to listen to the potentiometer as when scrolling trough I don't want to change the servos I don't want to change.
But it isn't working and I am not to fluent at coding since i am still in school and haven't had that much experience with arduino and I would like some help.
Here is the code:
#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
int potpin = A0;
int val = 0;
int servoNo = 0;
int active =0;
int leftBut = 0;
int rightBut = 1;
int midBut = 2;
int ledPins[] = {4,5,6,7,8};
void setup()
{
myservo1.attach(9);
myservo2.attach(10);
myservo3.attach(11);
myservo4.attach(12);
myservo5.attach(13);
pinMode(leftBut, INPUT);
pinMode(rightBut, INPUT);
pinMode(midBut, INPUT);
pinMode(ledPins[1], INPUT);
pinMode(ledPins[2], INPUT);
pinMode(ledPins[3], INPUT);
pinMode(ledPins[4], INPUT);
pinMode(ledPins[5], INPUT);
Serial.begin(9600);
}
void loop()
{
int servoNo = 0;
if (Serial.available())
{
Serial.write(servoNo);
}
int leftButPress = digitalRead(leftBut);
int midButPress = digitalRead(midBut);
int rightButPress = digitalRead(rightBut);
if (leftButPress = HIGH)
{
servoNo - 1;
}
if (rightButPress = HIGH)
{
servoNo + 1;
}
if (midButPress = HIGH)
{
active = 1;
}
else
{
active = 0;
}
if (servoNo = 6)
{
servoNo = 0;
}
if (servoNo = -1)
{
servoNo = 6;
}
digitalWrite(ledPins[servoNo], HIGH);
if (active = 1)
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
if(servoNo = 0) myservo1.write(val);
if(servoNo = 1) myservo2.write(val);
if(servoNo = 2) myservo3.write(val);
if(servoNo = 3) myservo4.write(val);
if(servoNo = 4) myservo5.write(val);
delay(15);
}
}