0% found this document useful (0 votes)
45 views1 page

Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views1 page

Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <Servo.

h>
Servo myservo1;
Servo myservo2;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
myservo1.attach(9);
myservo2.attach(10);

void loop() {
int x = digitalRead(2);
if (x== LOW){
int y = analogRead(A1);
y=map(y,0,1023,0,180);
Serial.print("angle of motor 1: ");
Serial.print(y);
Serial.print("||angle of motor 2:");
Serial.println(y);
delay(15);
myservo1.write(y); //angle of servo 1
myservo2.write(y); //angle of servo 2
}
else{
int y = analogRead(A1);
y=map(y,0,1023,180,0);
Serial.print("angle of motor 1: ");
Serial.print(y);
Serial.print("||angle of motor 2:");
Serial.println(180-y);
delay(15);
myservo1.write(y); //angle of servo 1
myservo2.write(180-y); //angle of servo 2
}
}

You might also like