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 a new Example : Servo Stop #45

Open
wants to merge 6 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
36 changes: 36 additions & 0 deletions examples/Servo-Stop/Servo-Stop.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <Servo.h>
#define trigPin 4
#define echoPin 2

Servo myservo; // create servo object to control a servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Use correct class name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not done.

int pos = 0; // variable to store the servo position
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop() {
// put your main code here, to run repeatedly:
long duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
digitalWrite(trigPin, LOW);

Serial.print(distance);
Serial.print("\n");

if (distance < 17)
myservo.write(0); // tell servo to go to position 0
else
myservo.write(90); // tell servo to go to position 90



}