Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo servo;
- int buttonPin =2;
- int buttonState=0;
- int ledPin = 9;
- int servoPin=10;
- void setup() {
- Serial.begin(9600);
- pinMode(buttonPin, OUTPUT);
- pinMode(ledPin, OUTPUT);
- servo.attach(servoPin);
- }
- void loop() {
- buttonState =digitalRead(buttonPin);
- // if button is pressed, the buttonState is HIGH:
- if (buttonState == HIGH) {
- // Gate Open
- digitalWrite(ledPin, HIGH);
- servo.write(90);
- delay(1000);
- } else {
- // Gate Open
- digitalWrite(ledPin, LOW);
- servo.write(0);
- delay(1000);
- }
- delay(100);
- }
Add Comment
Please, Sign In to add comment