/*
Controlling servo positions for robot arm in Engineering III Honors.
Created By: Stephen Collins
Date 2-(17-x)-2016
*/
#include <Servo.h>
Servo servo1; // servo that provides rotation for arm
Servo servo2;
Servo servo3;
Servo servo4;
int potpin0 = analogRead (A0); // connect to pin 0 controls servo1
int val0; // attaches the servo on pin 4-7 to the servo object
int potpin1 = analogRead (A1); // connect to pin 1 controls servo2
int val1;
int potpin2 = analogRead (A2); // connect to pin 2 controls servo3
int val2;
int potpin3 = analogRead (A3); // connect to pin 3 controls servo4
int val3;
void setup() {
servo1.attach(9); // attaches the servo on pin 4-7 to the servo object
servo2.attach(10);
servo3.attach(11);
servo4.attach(12);
}
void loop() {
val0 = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo1.write(val0); // sets the servo position according to the scaled value
val1 = analogRead(A1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo2.write(val1); // sets the servo position according to the scaled value
val2 = analogRead(A2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo3.write(val2); // sets the servo position according to the scaled value
val3 = analogRead(A3); // reads the value of the potentiometer (value between 0 and 1023)
val3 = map(val3, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo4.write(val3); // sets the servo position according to the scaled value
}