// setup variables
const int Button = 2; // button is connected to digital pin 2
const int Motor1 = 9; // motor1 is connected to digital pin 9
const int LED = 8; // LED is connected to digital pin 8
void setup () {
pinMode (Button, INPUT); // button gives info
pinMode (Motor1, OUTPUT); // motor1 is given info
pinMode(LED, OUTPUT); // LED is given info
}
void loop (){
int val; //need to first define a variable in order to use it
val= digitalRead(Button);
if(val==HIGH){
digitalWrite(Motor1,HIGH); // if button is pressed, motor is on
delay (30000); //wait 30 seconds, change to however long it takes to reach 30 ft
}else{
digitalWrite(Motor1, LOW); // if button is not pressed, motor is off
analogWrite(Motor1, 230); // speed of motor, # can range from 1 to 255 (slowest to fastest)
if(val==HIGH){
digitalWrite(LED, HIGH); //If button is pressed, LED is on
}else{
digitalWrite(LED, LOW); // otherwise LED is off
}
}
}