Created
July 22, 2015 18:14
-
-
Save DzikuVx/354d0ee6eba1bbd87f13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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