ROBOT ARM:-
#include <Servo.h>
int Servopin1=5;
int Servopin2=6;
int Servopin3=9;
int Servopin4=10;
int pot1=A1;
int pot2=A2;
int pot3=A3;
int pot4=A4;
int potval1;
int potval2;
int potval3;
int potval4;
int Servopos1;
int Servopos2;
int Servopos3;
int Servopos4;
Servo myServo1;
Servo myServo2;
Servo myServo3;
Servo myServo4;
void setup() {
// put your setup code here, to run once:
pinMode(pot1,INPUT);
pinMode(pot2,INPUT);
pinMode(pot3,INPUT);
pinMode(pot4,INPUT);
Serial.begin(9600);
myServo1.attach(Servopin1);
myServo2.attach(Servopin2);
myServo3.attach(Servopin3);
myServo4.attach(Servopin4);
}
void loop() {
// put your main code here, to run repeatedly:
potval1=analogRead(pot1);
potval2=analogRead(pot2);
potval3=analogRead(pot3);
potval4=analogRead(pot4);
Servopos1=map(potval1, 0, 1023, 0, 175);
Servopos2=map(potval2, 0, 1023, 0, 175);
Servopos3=map(potval3, 0, 1023, 0, 175);
Servopos4=map(potval4, 0, 1023, 0, 175);
myServo1.write(Servopos1);
myServo2.write(Servopos2);
myServo3.write(Servopos3);
myServo4.write(Servopos4);
delay(50);
}
0 Comments