Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15682

Controlling Multiple Servos Separately And Together

$
0
0

Hi, I was wondering if anyone would know the code for controlling multiple servos with multiple potentiometers, then using a button to toggle to a state where a separate potentiometer controls all of the servos at once. In my project, I have 4 servos that I want to first be controlled by 4 seperate potentiometers, then to have a button toggle so that all 4 servos are controlled by the movements of a fifth potentiometer. Is this possible? I have tried to find some code for this, but both it and the hardware don't seem to be working.

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

int pot1pin = A1;
int input1;
int pot2pin = A2;
int input2;
int pot3pin = A3;
int input3;
int pot4pin = A4;
int input4;
int pot5pin = A5;
int input5;

const int buttonPin = 9;

void setup() {
  servo1.attach(10);
  servo2.attach(11);
  servo3.attach(12);
  servo4.attach(13);

  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH); // Activate internal pull-up resistor  
  Serial.begin(9600);
}

void loop() {
  input1 = analogRead(pot1pin);
  input1 = map(input1, 0, 1023, 0, 180);
  servo1.write(input1);
  delay(15);

  input2 = analogRead(pot2pin);
  input2 = map(input2, 0, 1023, 0, 180);
  servo2.write(input2);
  delay(15);

  input3 = analogRead(pot3pin);
  input3 = map(input3, 0, 1023, 0, 180);
  servo3.write(input3);
  delay(15);

  input4 = analogRead(pot4pin);
  input4 = map(input4, 0, 1023, 0, 180);
  servo4.write(input4);
  delay(15);

5 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 15682

Latest Images

Trending Articles



Latest Images