/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
int button = 3;
int m1 = 6;
int m2 = 5;
int h1 = 7;
int k1 = 4;
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(button, INPUT_PULLUP);
pinMode(m1, OUTPUT);
pinMode(m2, OUTPUT);
pinMode(h1, OUTPUT);
pinMode(k1, OUTPUT);
}
void loop() {
if (digitalRead(button)==LOW)
{ digitalWrite(m1,HIGH);
int pencacah;
do
{ digitalWrite(h1, HIGH);
delay(2000);
digitalWrite(h1, LOW);
for (int y=1; y<=3 ;y++)
{ digitalWrite(k1,HIGH);
myservo.write(180); // sets the servo position according to the scaled value
delay(2000);
digitalWrite(k1,LOW);
myservo.write(90);
delay(1000); // waits for the servo to get there
}
digitalWrite(m2,HIGH);
delay(2000);
digitalWrite(m2,LOW);
delay(1000);
pencacah++;
} while (pencacah<=3);
digitalWrite(m1,LOW);
delay(1000);
}
// waits for the servo to get there
}