/*
* Garage Door Opener - Damien Kee 2019
* Sevo motor connected to pin 10
* Red and Green LED's on 8 and 9 (330ohm resistors to GND)
* Button on Pin 3
*/
//Include to Servo Library that does all the nitty-gritty servo code
#include <Servo.h>
//LEDs are connected to pins 8 and 9, button is on 4
int GREEN = 9;
int RED = 8;
int button_pin = 4;
Servo door; //Define the Servo object
void setup() {
// put your setup code here, to run once:
door.attach(10); // Tell the Arduino there is a Servo attached pin 10
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(button_pin, INPUT_PULLUP);
}
void loop() {
door.write(5); // Tell the servo to go to the 0 degree position
digitalWrite(RED, HIGH); // Red light on, green light off
digitalWrite(GREEN, LOW);
//If the button gets pressed
if (digitalRead(button_pin) == LOW) {
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
door.write(90);
delay(2000);
}
}