I made this small section of code for the arduino:
/*
Door Lock
By Alex Mann
Based off of Button Example
This is a simple script that locks and unlock a door (acuator) and turns on a led
motor1 is to unlock
motor2 is to lock (Connect to switch that disconects the motor's circut when it is extended all the way out)
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 2; // the number of the pushbutton pins
const int buttonPin2 = 4;
const int buttonPin3 = 8;
const int buttonPin4 = 12;
const int ledPin1 = 3; // the number of the LED pins
const int ledPin2 = 5;
const int motorPin1 = 9; // the number of the motor pins
const int motorPin2 = 10;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin1);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(motorPin1, HIGH);
delay(3000);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(motorPin1, LOW);
} else {
buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(motorPin2, HIGH);
delay(5000);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin1, LOW);
digitalWrite(motorPin2, LOW);
}
} else {
buttonState = digitalRead(buttonPin3);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(motorPin1, HIGH);
delay(3000);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(motorPin1, LOW);
}
} else {
buttonState = digitalRead(buttonPin4);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(motorPin2, HIGH);
delay(5000);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin1, LOW);
digitalWrite(motorPin2, LOW);
}
}
}
and I get this error:
C:\Users\X\Documents\Arduino\Door_Unlock1\Door_Unlock1.ino: In function 'void loop()':
Door_Unlock1:63: error: 'else' without a previous 'if'
} else {
^
Door_Unlock1:73: error: 'else' without a previous 'if'
} else {
^
exit status 1
'else' without a previous 'if'
What does this mean and how do I fix it?