-
Notifications
You must be signed in to change notification settings - Fork 267
Added-missing-examples-of-Servo-library #52
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
Open
Engineer1999
wants to merge
2
commits into
arduino-libraries:master
Choose a base branch
from
Engineer1999:added-library-examples-of-servo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Controling multiple servo motors using attach() and detach() | ||
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); | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.