/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
#define UPBUTTON_PIN 6
#define DNBUTTON_PIN 7
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int UP_But_Sts_Old; // the previous state of button
int UP_But_Sts_Cur; // the current state of button
int DN_But_Sts_Old; // the previous state of button
int DN_But_Sts_Cur; // the current state of button
void setup() {
Serial.begin(9600);
Serial.println("Starting...");
pinMode(UPBUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
pinMode(DNBUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
UP_But_Sts_Cur = digitalRead(UPBUTTON_PIN);
DN_But_Sts_Cur = digitalRead(DNBUTTON_PIN);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
UP_But_Sts_Old = UP_But_Sts_Cur; // save the last state
UP_But_Sts_Cur = digitalRead(UPBUTTON_PIN); // read new state
if(UP_But_Sts_Old == HIGH && UP_But_Sts_Cur == LOW) {
Serial.println("The UP-button is pressed");
if (pos > 0) {
pos = pos - 30;}}
DN_But_Sts_Old = DN_But_Sts_Cur; // save the last state
DN_But_Sts_Cur = digitalRead(DNBUTTON_PIN); // read new state
if(DN_But_Sts_Old == HIGH && DN_But_Sts_Cur == LOW) {
Serial.println("The DN-button is pressed");
if (pos < 180) {
pos = pos + 30;}}
myservo.write(pos); // tell servo to go to position in variable 'pos'
//delay(300); // waits 15ms for the servo to reach the position
}