Hello, I'm working on a school project where I've got to press a button to start a sequence of lights that I can only have run once (so no loop) and I want nothing to happen until the button is pressed
int Distribution = 1; //LEDs
int Drones = 2; //LEDs
int Collection = 3; //LEDs
int Holding = 4; //LEDs
int Drive = 5; //LEDs
int Bridge = 6; //LEDs
int Quarters = 7; //LEDs
int Storage = 8; //LEDs
int AI = 9; //LEDs
int Galley = 10; //LEDs
int Button = 11; //Button PIN
void setup() {
pinMode(Distribution,OUTPUT);
pinMode(Drones,OUTPUT);
pinMode(Collection,OUTPUT);
pinMode(Holding,OUTPUT);
pinMode(Drive,OUTPUT);
pinMode(Bridge,OUTPUT);
pinMode(Quarters,OUTPUT);
pinMode(Storage,OUTPUT);
pinMode(AI,OUTPUT);
pinMode(Galley,OUTPUT);
pinMode(Button,INPUT);
//Button press to start sequence here
delay(4000); //initial speech
//room 1
digitalWrite(Distribution,HIGH);
delay(6000);
digitalWrite(Distribution,LOW);
delay(100);
//room 2
digitalWrite(Drones,HIGH);
delay(6000);
digitalWrite(Drones,LOW);
delay(100);
//room 3
digitalWrite(Collection,HIGH);
delay(6000);
digitalWrite(Collection,LOW);
delay(100);
//room 4
digitalWrite(Holding,HIGH);
delay(6000);
digitalWrite(Holding,LOW);
delay(100);
//room 5
digitalWrite(Drive,HIGH);
delay(6000);
digitalWrite(Drive,LOW);
delay(100);
//room 6
digitalWrite(Bridge,HIGH);
delay(6000);
digitalWrite(Bridge,LOW);
delay(100);
//room 7
digitalWrite(Quarters,HIGH);
delay(6000);
digitalWrite(Quarters,LOW);
delay(100);
//room 8
digitalWrite(Storage,HIGH);
delay(6000);
digitalWrite(Storage,LOW);
delay(100);
//room 9
digitalWrite(AI,HIGH);
delay(6000);
digitalWrite(AI,LOW);
delay(100);
//room 10
digitalWrite(Galley,HIGH);
delay(6000);
digitalWrite(Galley,LOW);
//final delay
delay(300);
//this is the end
//I don't want this to loop
}
void loop() {
}
It is just a bunch of leds that I want to start with a button press
FYI, I'm fairly new to this stuff so if you could explain what your doing that would be very helpful.
This is happening while another Arduino is playing an MP3 file that is about 2 minutes long, those delays are subject to change because I can't get the lights to turn on with the button!
And I have another question, at the start of the code, Pin 1 breifly turns on at the beginning of the code, is that something that just happens and I shouldn't use it?
So, its, not working anymore, when I upload the code, the code just starts and goes, doesn't loop, but doesn't matter if the button gets pressed or not.
int Distribution = 1; //LEDs
int Drones = 2; //LEDs
int Collection = 3; //LEDs
int Holding = 4; //LEDs
int Drive = 5; //LEDs
int Bridge = 6; //LEDs
int Quarters = 7; //LEDs
int Storage = 8; //LEDs
int AI = 9; //LEDs
int Galley = 10; //LEDs
int Button = 11; //Button PIN
void setup() {
pinMode(Distribution,OUTPUT);
pinMode(Drones,OUTPUT);
pinMode(Collection,OUTPUT);
pinMode(Holding,OUTPUT);
pinMode(Drive,OUTPUT);
pinMode(Bridge,OUTPUT);
pinMode(Quarters,OUTPUT);
pinMode(Storage,OUTPUT);
pinMode(AI,OUTPUT);
pinMode(Galley,OUTPUT);
pinMode(Button,INPUT);
//Button press to start sequence here
pinMode (Button, INPUT_PULLUP); // button pulls pin to ground
while (HIGH, digitalRead (Button));
delay(4000); //initial speech
//room 1
digitalWrite(Distribution,HIGH);
delay(6000);
digitalWrite(Distribution,LOW);
delay(100);
//room 2
digitalWrite(Drones,HIGH);
delay(6000);
digitalWrite(Drones,LOW);
delay(100);
//room 3
digitalWrite(Collection,HIGH);
delay(6000);
digitalWrite(Collection,LOW);
delay(100);
//room 4
digitalWrite(Holding,HIGH);
delay(6000);
digitalWrite(Holding,LOW);
delay(100);
//room 5
digitalWrite(Drive,HIGH);
delay(6000);
digitalWrite(Drive,LOW);
delay(100);
//room 6
digitalWrite(Bridge,HIGH);
delay(6000);
digitalWrite(Bridge,LOW);
delay(100);
//room 7
digitalWrite(Quarters,HIGH);
delay(6000);
digitalWrite(Quarters,LOW);
delay(100);
//room 8
digitalWrite(Storage,HIGH);
delay(6000);
digitalWrite(Storage,LOW);
delay(100);
//room 9
digitalWrite(AI,HIGH);
delay(6000);
digitalWrite(AI,LOW);
delay(100);
//room 10
digitalWrite(Galley,HIGH);
delay(6000);
digitalWrite(Galley,LOW);
//final delay
delay(300);
//this is the end
//I don't want this to loop
}
void loop() {
}
Are you sure that your wanted functionality is
microcontroller is switched on
wait for button-press
if button is pressed make LED-lightshow for a single time
never never ever make LED-light-show again
to repeat
waiting for button etc. power must be switched to off and on again?
Or do you want
each time the button is pressed make LED-Lightshow only once
then go back to wait for the next button-press?