Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo;
- #define button 4 // Der Taster ist auf Pin 4
- int pos = 30; // IST_Wert des Servos
- bool lastKey = LOW;
- void setup()
- {
- myservo.attach(5); // Der Servo ist auf Pin 5
- pinMode(pos, OUTPUT);
- pinMode(button, INPUT_PULLUP);
- }
- void loop() {
- if (digitalRead(button) == HIGH && lastKey == LOW) {
- for (pos = 30; pos <= 70; pos += 70) {
- myservo.write(pos);
- delay(10);
- }
- lastKey = HIGH;
- }
- if (digitalRead(button) == LOW && lastKey == HIGH) {
- for (pos = 70; pos >= 30; pos -= 70) {
- myservo.write(pos);
- delay(270);
- }
- lastKey = LOW;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment