-
Notifications
You must be signed in to change notification settings - Fork 267
calibrate example for Servo #49
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
bb23457
6001753
4b31d2e
a928daa
e69088d
8819502
be98aac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <Servo.h> | ||
Servo myservo; // create servo object to control a servo | ||
int input; // variable to read the value from the SerialMonitor | ||
int servoPin = 11; // set the Pin on Arduino, servo is attached | ||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
void setup() { | ||
myservo.attach(servoPin); // attaches the servo on servoPin to the servo object | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
if (Serial.available() > 0) { | ||
input = Serial.parseInt(); // reads the value from Serial | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the line ending menu of Serial Monitor set to anything other than "No line ending", there is an issue. For example, if I enter 42 in the Serial Monitor input field, I get this output:
"Newline" is the default setting of this menu, so it's likely many users will encounter this problem. The easiest solution would be to document the required line ending setting. Of course, many users won't read the directions, so they will still have the problem. There is also the issue of the 1 s delay before the input takes effect. Not a huge issue, but it doesn't provide a very responsive feeling to the interface. I explained the cause and described the fix for these issues here: #44 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok ill look into your suggestions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @per1234 should I mention in the document to use no line ending or should I try improvising code to work for newline? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The reason is because serial communication is relatively slow. The solution is to add a short delay before the "remove the line endings" code to allow the CR to be received, as I demonstrated in #44 (comment). |
||
myservo.write(input); // sets the servo position | ||
Serial.print("Servo set to "); | ||
Serial.print(input); | ||
Serial.println(" degree"); | ||
delay (1000); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.