is there any way for my arduino wait for me to push a button before going on with the code.
while (digitalRead(pin) ==HIGH);
or LOW
Yes.
What code are you talking about, attach it useing the </> icon.
Tell us where and what you want to do in it.
here is my code
void setup(){
pinMode(11, OUTPUT);
}
void loop(){
tone(11, 1500);
//wait for pushbutton to be pressed
noTone(11);
tone(11, 1400);
//wait for pushbutton to be pressed
}
/*Tones dependent on button presses
Circuit: pushbutton wired between pin 2 and any ground pin (goes LOW when pressed)
Buzzer/speaker between pin 11 and ground
*/
#define BUTTON_PIN 2
#define SPEAKER_PIN 11
#define DEBOUNCE_DELAY 5 //milliseconds - need to allow the button a few milliseconds to stop 'bouncing'
void setup(){
pinMode(SPEAKER_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop(){
tone(SPEAKER_PIN, 1500);
while (digitalRead(BUTTON_PIN) ==HIGH); //wait for the button to be pressed (LOW)
noTone(SPEAKER_PIN);
delay(DEBOUNCE_DELAY);
while (digitalRead(BUTTON_PIN) ==LOW); //wait for the button to be released
tone(SPEAKER_PIN, 1400);
delay(DEBOUNCE_DELAY);
while (digitalRead(BUTTON_PIN) ==HIGH); //wait for the button to be pressed (LOW)
//perhaps you wanted to turn this tone off?
delay(DEBOUNCE_DELAY);
while (digitalRead(BUTTON_PIN) ==LOW); //wait for the button to be released
delay(DEBOUNCE_DELAY);
//maybe more stuff here?
}
One small suggestion:
while (digitalRead(BUTTON_PIN) ==HIGH);
IMO, for readability, I would change lines like these to
while (digitalRead(BUTTON_PIN) ==HIGH)
{
//wait for the button to be pressed
}