/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo myservo_0; // create servo object to control a servo
int potpin0 = A0; // analog pin used to connect the potentiometer
int val_0; // variable to read the value from the analog pin
Servo myservo_1; // create servo object to control a servo
int potpin1 = A1; // analog pin used to connect the potentiometer
int val_1;
Servo myservo_2; // create servo object to control a servo
int potpin2 = A2; // analog pin used to connect the potentiometer
int val_2;
Servo myservo_3;
int potpin3 = A3;
int val_3;
Servo myservo_4;
int potpin4 = A4;
int val_4;
Servo myservo_5;
int potpin5 = A5;
int val_5;
//stepper setup
const int dirPin = 12;
const int stepPin = 13;
const int stepsPerRevoIution = 200;
void setup()
{
myservo_0.attach(3);
myservo_1.attach(5);// attaches the servo on pin 9 to the servo object
myservo_2.attach(6);
myservo_3.attach(9);
myservo_4.attach(10);
myservo_5.attach(11);
//stepper setup
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
}
void loop()
{
val_0 = analogRead(potpin0); // reads the value of the potentiometer (value between 0 and 1023)
val_0 = map(val_0, 0, 1023, 0, 180); // scale it for use with the servo (value between 0 and 180)
myservo_0.write(val_0); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
val_1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val_1 = map(val_1, 0, 1023, 0, 180); // scale it for use with the servo (value between 0 and 180)
myservo_1.write(val_1); // sets the servo position according to the scaled value
delay(15);
val_2 = analogRead(potpin2);
val_2 = map(val_2, 0, 1023, 0, 180);
myservo_2.write(val_2);
delay(15);
val_3 = analogRead(potpin3);
val_3 = map(val_3, 0, 1023, 0, 180);
myservo_3.write(val_3);
delay(15);
val_4 = analogRead(potpin4);
val_4 = map(val_4, 0, 1023, 0, 180);
myservo_4.write(val_4);
delay(15);
val_5 = analogRead(potpin5);
val_5 = map(val_5, 0, 1023, 0, 180);
myservo_5.write(val_5);
delay(15);
//stepper setup
digitalWrite(dirPin, HIGH);
for (int x = 0; x < stepsPerRevoIution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
}