Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added-missing-examples-of-Servo-library #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions examples/AnalogInput/AnalogInput.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Controling multiple servo motors using attach() and detach()
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
by Bhargav Patel <https://github.com/Engineer1999/>

*/

#include <Servo.h>

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

void setup()
{
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
Serial.begin(9600); // initializing serial communication with 9600 baud rate
myservo.attach(10); // attaches the servo on pin 10 to the servo object
myservo.writeMicroseconds(500); // setting initial angle to 0 (analog value = 500 [any value less than 700])

}

void loop() {
angle = myservo.read(); // read the value of the current angle on servo motor
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
Serial.print("Inital angle:- ");
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println(angle); // print angle on servo motor
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
myservo.writeMicroseconds(1000); // setting angle to 45 (analog value = 1000)
delay(1000); // delay of 1 second

angle = myservo.read();
Serial.print("Angle at input 1000:- ");
Serial.println(angle);
myservo.writeMicroseconds(1500); // setting angle to 90 (analog value = 1000)
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
delay(1000);

angle = myservo.read();
Serial.print("Angle at input 1500:- ");
Serial.println(angle);
myservo.writeMicroseconds(3000); // setting angle to 180 (analog value = 3000 [any value greater than 2300])
delay(1000);

angle = myservo.read();
Serial.print("Angle at input 3000:- ");
Serial.println(angle);

}
58 changes: 58 additions & 0 deletions examples/MultipleServoMotors/MultipleServoMotors.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Controling multiple servo motors using attach() and detach()
by Bhargav Patel <https://github.com/Engineer1999/>
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved

*/

#include <Servo.h>

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

int angle; // variable to read the angle value of servo motor

void setup()
{


Serial.begin(9600); // initializing serial communication with 9600 baud rate

myservo.attach(10); // attaches the servo on pin 10 to the servo object
if (myservo.attached()){ // cheack whether servo motor is attached or not
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Servo motor attached to pin 10");

myservo.write(0); // setting angle of servo motor at 0 degree
delay(1000); // delay of 1 second
myservo.write(90); // setting angle of servo motor at 90 degree
delay(1000);
myservo.write(180); // setting angle of servo motor at 90 degree
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
delay(1000);
} else{
Serial.println("Servo motor attachement failed");
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
}


myservo.attach(12); // attaches the servo on pin 12 to the servo object
if (myservo.attached()){ // cheack whether servo motor is attached or not
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Servo motor attached to pin 12");

myservo.write(0);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
} else{
Serial.println("Servo motor attachement failed");
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
}

myservo.detach(); // detach the servo motor
if (myservo.attached()){ // cheack whether servo motor is attached or not
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Servo motor is still attached");
} else{
Serial.println("Servo motor is still detached");
Engineer1999 marked this conversation as resolved.
Show resolved Hide resolved
}

}

void loop() {
}