Skip to content

Instantly share code, notes, and snippets.

@DzikuVx
Created July 22, 2015 18:14
Show Gist options
  • Save DzikuVx/354d0ee6eba1bbd87f13 to your computer and use it in GitHub Desktop.
Save DzikuVx/354d0ee6eba1bbd87f13 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo servo;
const int PIN_BUTTON = 6;
const int PIN_SERVO = 5;
int pos = 1500;
int prevButtonState = HIGH;
int currentButtonState = HIGH;
void setup() {
servo.attach(PIN_SERVO);
servo.writeMicroseconds(pos);
pinMode(PIN_BUTTON, INPUT_PULLUP);
}
void loop() {
currentButtonState = digitalRead(PIN_BUTTON);
if (currentButtonState == LOW && prevButtonState == HIGH) {
pos = pos + 500;
if (pos > 2000) {
pos = 1000;
}
servo.writeMicroseconds(pos);
}
prevButtonState = currentButtonState;
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment