I fixed it. You were missing a bunch of "}" The first error message you had was due to the loop()
started before a "}" closed the previous void setup()
.
Notice that the code here is in a nice seperate box, which makes reading it easier. Also note the indentation - the editor does it if you press ^T. Read the top post on how to post to get these details right.
I do not know if this is the logic you want. The code you supplied had some "}" inside comments (after a "//" on the same line) and thus do not count. I have just sprinkled "}" at the end until it compiled.
// define pins to be used
int S1 = 2; //switch 1
int S2 = 3;
int S3 = 4;
int L1 = 5; // light 1
int L2 = 6;
int L3 = 7;
int B = 8; //buzzer
void setup() { // initialize the digital pins. // assume switches will wire from ground to input pins
pinMode(S1, INPUT_PULLUP);
pinMode(S2, INPUT_PULLUP);
pinMode(S3, INPUT_PULLUP);
pinMode(L1, OUTPUT); // leds wired from output pin to ground
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(B, OUTPUT); // buzzer wired from output pin to ground
}
void loop() {
if (!digitalRead(S1)) {
digitalWrite(L1,HIGH); // turn on lamp 1
digitalWrite(B,HIGH); // turn on buzzer
delay(500); // wait 2 seconds
digitalWrite(B,LOW); // turn off buffer
delay(5000); // wait 28 more seconds
digitalWrite(L1,LOW); // turn off lamp 1 }
if (!digitalRead(S2)) {
digitalWrite(L2,HIGH); // turn on lamp 2
digitalWrite(B,HIGH); // turn on buzzer
delay(500); // wait 2 seconds
digitalWrite(B,LOW); // turn off buffer
delay(5000); // wait 28 more seconds
digitalWrite(L2,LOW); // turn off lamp 2 }
if (!digitalRead(S3)) {
digitalWrite(L3,HIGH); // turn on lamp 3
digitalWrite(B,HIGH); // turn on buzzer
delay(500); // wait 2 seconds
digitalWrite(B,LOW); // turn off buffer
delay(5000); // wait 28 more seconds
digitalWrite(L3,LOW); // turn off lamp 3
}
}
}
}
Also note that code like delay(500) ; // wait 2 seconds
is very confusing. The code says half a second, the comment says 2 seconds. Which did you want?