#include <Servo.h>
const int SERVO =9;
const int IR =0;
Servo myServo;
int pos = 0; // variable to store the servo position
void setup()
{
Serial.begin(9600);
myServo.attach(SERVO); // attach the servo
}
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
if (analogRead(IR) > 200)
{
delay(500);
}
}
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
if (analogRead(IR) > 200)
{
delay(500);
}
}
}
const int SERVO =9;
const int IR =0;
Servo myServo;
int pos = 0; // variable to store the servo position
void setup()
{
Serial.begin(9600);
myServo.attach(SERVO); // attach the servo
}
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
if (analogRead(IR) > 200)
{
delay(500);
}
}
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
if (analogRead(IR) > 200)
{
delay(500);
}
}
}
No comments:
Post a Comment