lovelymondayss

Untitled

Oct 22nd, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo servo;
  3. int buttonPin =2;
  4. int buttonState=0;
  5. int ledPin = 9;
  6. int servoPin=10;
  7. void setup() {
  8. Serial.begin(9600);
  9. pinMode(buttonPin, OUTPUT);
  10. pinMode(ledPin, OUTPUT);
  11. servo.attach(servoPin);
  12. }
  13. void loop() {
  14. buttonState =digitalRead(buttonPin);
  15. // if button is pressed, the buttonState is HIGH:
  16. if (buttonState == HIGH) {
  17. // Gate Open
  18. digitalWrite(ledPin, HIGH);
  19. servo.write(90);
  20. delay(1000);
  21. } else {
  22. // Gate Open
  23. digitalWrite(ledPin, LOW);
  24. servo.write(0);
  25. delay(1000);
  26. }
  27. delay(100);
  28. }
Add Comment
Please, Sign In to add comment