8000 New Example: Input by hmzakhalid · Pull Request #44 · arduino-libraries/Servo · GitHub
[go: up one dir, main page]

Skip to content

New Example: Input #44

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
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
New Example input
Controlling the shaft of servo using serial input
  • Loading branch information
hmzakhalid committed Mar 20, 2020
commit a45a57c19f119ec1f330d06a2a40a122e92272a6
26 changes: 26 additions & 0 deletions examples/Input/Input.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Controlling a servo position using serial input
by Hamza Khalid https://github.com/hmzakhalid

*/

#include <Servo.h>

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


int pos = 0; // initial Position of the Shaft (max is 180)

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.println("Enter Position from 1 to 180");
}


void loop() {
pos = Serial.read(); // Reading the input from the serial monitor and storing it in'pos'
if(pos > 0){ // checks if there is any input
myservo.write(pos); // tell servo to go to that position
delay(15); // waits 15ms for the servo to reach the position
}
}
0