hi,
im trying to program a sequence of things to happen when i push a button. i have spent hours trying to work out why my code dosnt work. when uploaded it does the sequence perfectly but isnt controled by the button. it just runs without any inputs. Please could someone help me as to why it dosnt work?
Heres my code:
int val = 0;
int button = 2;
void setup() {
pinMode(2, INPUT); //Push Button
pinMode(29, OUTPUT); //warning and explosion sound card
pinMode(24, OUTPUT); //smoke machine
pinMode(25, OUTPUT); //fake flame
pinMode(26, OUTPUT); //water sound card
pinMode(27, OUTPUT); //warning beacon
pinMode(28, OUTPUT); //Finsihed led
}
void loop() {
val = digitalRead(button); //Is Button pressed?
if(val == HIGH) { //Yes! its pressed, excute these things...
digitalWrite(28, LOW); //Finshed led off
digitalWrite(26, HIGH); //sound card press
delay(1000); // wait for a second
digitalWrite(26, LOW); // sound card stop pressing
delay(14000); // wait till sound finished
digitalWrite(27, HIGH); //warning beacon on
digitalWrite(29, HIGH); //warning explosion sound card press
delay(1000); // wait 1 sec
digitalWrite(29, LOW); //sound card press off
delay(6000); //wait 6 secs
digitalWrite(24, HIGH); //smoke on
delay(4000); // 4 secs smoke
digitalWrite(24, LOW); //smoke off
digitalWrite(25, HIGH); //fake flame on
delay(6000); //wait 6 sec
digitalWrite(29, LOW); //ALL OFF
digitalWrite(24, LOW);
digitalWrite(25, LOW);
digitalWrite(26, LOW);
digitalWrite(27, LOW);
digitalWrite(28, HIGH); // Finshed led
}
else {
digitalWrite(29, LOW); //ALL OFF
digitalWrite(24, LOW);
digitalWrite(25, LOW);
digitalWrite(26, LOW);
digitalWrite(27, LOW);
digitalWrite(28, HIGH);
}
}
Thanks in advance