Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Servo myservo;
  2.  
  3. int pos = 0;
  4. int button1 = D2;
  5. int servloop = 0;
  6.  
  7. void setup() {
  8.  
  9. myservo.attach(D1);
  10. myservo.write(30);
  11. pinMode(D5, OUTPUT);
  12. pinMode(button1, INPUT_PULLUP);
  13. Serial.begin(9600);
  14. Serial.println(servloop);
  15. }
  16.  
  17. void loop() {
  18. Serial.println(servloop);
  19.  
  20. if (servloop > 0) {
  21. servloop--;
  22. }
  23.  
  24. if(digitalRead(button1) == LOW){
  25. while (servloop < 3) {
  26. myservo.write(0);
  27. digitalWrite(D5, HIGH);
  28. delay(1000);
  29. myservo.write(90);
  30. digitalWrite(D5, LOW);
  31. delay(1000);
  32. servloop ++;
  33. }
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement