Lab_interaccio/2016/pintor/pintor.ino

28 lines
755 B
Arduino
Raw Normal View History

2025-02-25 21:29:42 +01:00
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int PIN=A0;
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
pinMode(PIN, INPUT);
digitalWrite(PIN, HIGH);
myservo.attach(3); // attaches the servo on pin 9 to the servo object
}
void loop() {
if (digitalRead(PIN))
{
myservo.write(90); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
else
{
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}