Robot Arm Code
Robot Arm Code
#include <Servo.h>
void setup() {
servo1.attach(5); // Set up everything and will run once; attach servos and
define the pin modes
servo2.attach(6);
servo3.attach(9);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
pot1Val = analogRead(pot1); // This will read the values from the potentimeters
and store it...
pot1Angle = map(pot1Val, 0, 1023, 0, 179); // ... and this will map the values
from the potentiometers to values the servos can use and store it for later use
pot2Val = analogRead(pot2);
pot2Angle = map(pot2Val, 0, 1023, 0, 179);
pot3Val = analogRead(pot3);
pot3Angle = map(pot3Val, 0, 1023, 0, 179);
servo1.write(pot1Angle); // These will make the servos move to the mapped angles
servo2.write(pot2Angle);
servo3.write(pot3Angle);