Advertisement
batuhk

Arduino Assignment 9

May 28th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myServo;
  4. int servoPin = 9;
  5. int pos = 0;
  6. int buttonPinL = 2;
  7. int buttonPinR = 3;
  8. int buttonL = 0;
  9. int buttonR = 0;
  10.  
  11. void setup() {
  12. Serial.begin(9600);
  13. myServo.attach(servoPin);
  14. pinMode(buttonPinL, INPUT);
  15. pinMode(buttonPinR, INPUT);
  16.  
  17. }
  18.  
  19. void loop() {
  20. buttonL = digitalRead(buttonPinL);
  21. buttonR = digitalRead(buttonPinR);
  22.  
  23. if (buttonL == HIGH) {
  24. Serial.print("links");
  25. for (pos = 0; pos < 180; pos +=180) {
  26. myServo.write(pos);
  27. }
  28. } else if (buttonR == HIGH) {
  29. Serial.print("rechts");
  30. for (pos = 180; pos >= 1; pos -=180) {
  31. myServo.write(pos);
  32. }
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement