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 an example #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
39 changes: 39 additions & 0 deletions examples/Read/Read.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Read
by BARRAGAN <http://barraganstudio.com>
per1234 marked this conversation as resolved.
Show resolved Hide resolved
This example code is in the public domain.

Example to sweep and display the angle in Serial Monitor

modified 18 Mar 2020
by S Jeeva
*/

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position
int currPos; // variable to read the current position

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // Begin the Serial at 9600 baud rate
}

void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
currPos = myservo.read(); // Read the angle of position
Serial.println(currPos); // Print the angle of position in serial monitor
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
currPos = myservo.read(); // Read the angle of position
Serial.println(currPos); // Print the angle of position in serial monitor
}
}