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

New Example: Input #44

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 5 commits
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
28 changes: 28 additions & 0 deletions examples/Input/Input.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Controlling a servo position using serial input
by Hamza Khalid https://github.com/hmzakhalid

hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
*/

#include <Servo.h>

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


hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
int pos = 0; // initial Position of the Shaft (max is 180)
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
Serial.println("Enter Position from 1 to 180");
}


void loop() {

if(Serial.available() > 0){ // checks if there is any input on the serial monitor
pos = Serial.read(); // Reading the input from the serial monitor and storing it in'pos'
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
myservo.write(pos); // tell servo to go to that position
delay(15); // waits 15ms for the servo to reach the position
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
}
}