You should be using digitalRead(8)
instead of digitalWrite(8, HIGH)
. Your sketch is also missing some curly brackets.
void setup(){
pinMode(4, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, INPUT);
}
void loop(){
if(digitalRead(8) == HIGH){
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
}
else{
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
digitalWrite(4,HIGH);
delay(1500);
digitalWrite(4,LOW);
}
The use of delay()
will block the sketch from doing anything else, and should be replaced with a millsmillis()
timer. Have a look at the BlinkWithoutDelay
example in the IDE.