Hi! I'm working on this code and it was working fine until I started messing with it, then I deleted the things I added and tried uploading it but I keep getting "Expected Unidentified -id before "if".
I'm in desperate need of help, so any advice will be much appreciated thank you!
*/
// declare what constants won't change. They are used here to set pin numbers.
const int buttonPin1 = 10; // first pushbutton on pin 10
const int buttonPin2 = 11; // second pushbutton on pin 11
const int buttonPin3 = 12; // third pushbutton on pin 12
const int buttonPin4 = 13; // fourth pushbutton on pin 13
const int ledPin1 = 5; // ledPin on pin 5
const int ledPin2 = 6;
const int speaker = 7;
// declare what variables will change:
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
void setup () { // run once at sketch startup
Serial.begin(9600); // begin serial
pinMode (buttonPin1, INPUT); // buttonPin1 as input
pinMode (buttonPin2, INPUT); // buttonPin2 as input
pinMode (buttonPin3, INPUT); // buttonPin3 as input
pinMode (buttonPin4, INPUT); // buttonPin4 as input
pinMode (ledPin1, OUTPUT); // ledPin1 as output
pinMode (ledPin2, OUTPUT);
pinMode (speaker, OUTPUT);
}
void loop () {
digitalWrite (ledPin1, LOW);
buttonState1 = digitalRead (buttonPin1);
// Serial.println (buttonState1);
buttonState2 = digitalRead (buttonPin2);
//Serial.println (buttonState2);
buttonState3 = digitalRead (buttonPin3);
//Serial.println (buttonState3);
buttonState4 = digitalRead (buttonPin4);
//Serial.println (buttonState4);
}
if(digitalRead (buttonPin4) ==LOW) {
Serial.println ("4");
delay (1000);
if ((digitalRead (buttonPin1) ==LOW) && (digitalRead (buttonPin2)== LOW)) {
Serial.println ("1 and 2");
delay (1000);
if (digitalRead (buttonPin3) ==LOW) {
Serial.println ("3");
delay (1000);
digitalWrite (ledPin1, HIGH);
tone (speaker, 125);
delay (2000);
noTone (speaker);
} else {
digitalWrite( ledPin1, HIGH);
tone (speaker, 400);
delay (1000);
noTone (speaker);
digitalWrite (ledPin2, LOW);
}
}