0% found this document useful (0 votes)
3 views2 pages

Contoh Coding

The Arduino sketch controls two servo motors and an LED. It includes multiple loops to move the servos between specified angles with delays for smooth movement. However, there are potential issues with overlapping servo movements and the angle ranges that may exceed the servo's capabilities, particularly in the last loop where it attempts to move from 90 to 31 degrees for myservo1.

Uploaded by

sulianto.ahe
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)
3 views2 pages

Contoh Coding

The Arduino sketch controls two servo motors and an LED. It includes multiple loops to move the servos between specified angles with delays for smooth movement. However, there are potential issues with overlapping servo movements and the angle ranges that may exceed the servo's capabilities, particularly in the last loop where it attempts to move from 90 to 31 degrees for myservo1.

Uploaded by

sulianto.ahe
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/ 2

Below are my ardunio sketch, can anyone give me some advice on what's wrong?

Thanks
a lot.

#include <Servo.h>

Servo myservo1; // create servo object to control a servo


Servo myservo2;
// two servo objects created

int ledpin3 = 3;

void setup() {
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);

pinMode(ledpin3, OUTPUT);
}

void loop() {

digitalWrite(ledpin3, HIGH);

for (int pos = 30; pos <= 90; pos += 1) { // goes from 30 degrees to 90 degrees

// in steps of 1 degree

myservo1.write(pos); // tell servo to go to position in variable ‘pos’

delay(15); // waits 15ms for the servo to reach the position


}

for (int pos = 30; pos <= 59; pos += 1) { // goes from 30 degrees to 60 degrees

// in steps of 1 degree

myservo2.write(pos); // tell servo to go to position in variable ‘pos’

delay(15); // waits 15ms for the servo to reach the position


}

for (int pos = 60; pos >= 30; pos -= 1) { // goes from 60 degrees to 30 degrees

// in steps of 1 degree

myservo2.write(pos); // tell servo to go to position in variable ‘pos’

delay(15);
}
delay(1000);

for (int pos = 91; pos <= 150; pos += 1) { // goes from 91 degrees to 150 degrees

// in steps of 1 degree

myservo1.write(pos); // tell servo to go to position in variable ‘pos’

delay(15); // waits 15ms for the servo to reach the position

}
delay(1000);

for (int pos = 151; pos >= 91; pos -= 1) { // goes from 151 degrees to 91degrees

// in steps of 1 degree

myservo1.write(pos); // tell servo to go to position in variable ‘pos’

delay(15); // waits 15ms for the servo to reach the position


}

for (int pos = 30; pos <= 59; pos += 1) { // goes from 30 degrees to 60 degrees

// in steps of 1 degree

myservo2.write(pos); // tell servo to go to position in variable ‘pos’

delay(15); // waits 15ms for the servo to reach the position


}

for (int pos = 60; pos >= 30; pos -= 1) { // goes from 60 degrees to 30 degrees

// in steps of 1 degree

myservo2.write(pos); // tell servo to go to position in variable ‘pos’

delay(15);
}
delay(1000);

for (int pos = 90; pos >= 31; pos -= 1) { // goes from 90 degrees to 30 degrees

// in steps of 1 degree

myservo1.write(pos); // tell servo to go to position in variable ‘pos’

delay(15); // waits 15ms for the servo to reach the position


}
}

You might also like