jp112

Servo

Jun 18th, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myservo;
  3.  
  4. #define button 4  // Der Taster ist auf Pin 4
  5.  
  6. int pos = 30;    // IST_Wert des Servos
  7. bool lastKey = LOW;
  8.  
  9. void setup()
  10. {
  11.   myservo.attach(5);  // Der Servo ist auf Pin 5
  12.   pinMode(pos, OUTPUT);
  13.   pinMode(button, INPUT_PULLUP);
  14. }
  15.  
  16. void loop() {
  17.   if (digitalRead(button) == HIGH && lastKey == LOW) {
  18.     for (pos = 30; pos <= 70; pos += 70) {
  19.       myservo.write(pos);
  20.       delay(10);
  21.     }
  22.     lastKey = HIGH;
  23.   }
  24.  
  25.   if (digitalRead(button) == LOW && lastKey == HIGH) {
  26.     for (pos = 70; pos >= 30; pos -= 70) {
  27.       myservo.write(pos);
  28.       delay(270);
  29.     }
  30.     lastKey = LOW;
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment