-
Notifications
You must be signed in to change notification settings - Fork 266
Added a new Example : Servo Stop #45
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 1 commit
629463c
a03a595
5791bd9
7e76d93
723279a
feddadd
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,36 @@ | ||||||
#include <Servo.h> | ||||||
#define trigPin 4 | ||||||
#define echoPin 2 | ||||||
|
||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Servo myservo; // create servo object to control a servo | ||||||
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.
Suggested change
Use correct class name. 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. PR Updated 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. This was not done. |
||||||
int pos = 0; // variable to store the servo position | ||||||
void setup() { | ||||||
// put your setup code here, to run once: | ||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Serial.begin(9600); | ||||||
pinMode(trigPin, OUTPUT); | ||||||
pinMode(echoPin, INPUT); | ||||||
myservo.attach(9); // attaches the servo on pin 9 to the servo object | ||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
void loop() { | ||||||
// put your main code here, to run repeatedly: | ||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
long duration, distance; | ||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
digitalWrite(trigPin, HIGH); | ||||||
delayMicroseconds(10); | ||||||
digitalWrite(trigPin, LOW); | ||||||
|
||||||
duration = pulseIn(echoPin, HIGH); | ||||||
distance = (duration / 2) / 29.1; | ||||||
digitalWrite(trigPin, LOW); | ||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Serial.print(distance); | ||||||
Serial.print("\n"); | ||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if (distance < 17) | ||||||
myservo.write(0); // tell servo to go to position 0 | ||||||
else | ||||||
myservo.write(90); // tell servo to go to position 90 | ||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
|
||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} |
Uh oh!
There was an error while loading. Please reload this page.