Hi does anyone know what I need to place down for a code in order to get the buzzer to stop playing notes after all the LEDS are on and while the button is still held?
#define Tone_G 392 // Define Tone G
#define Tone_A 440 // Define Tone A
#define Tone_B 494 // Define Tone B
const int buttonPin = 8;
const int Sound = 12; // For the speakers - sound will occur on Pin 12
const int ledPin4 = 4;
const int ledPin3 = 3;
const int ledPin2 = 2;
int buttonState = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin4, INPUT);
pinMode(ledPin3, INPUT);
pinMode(ledPin2, INPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(Sound, INPUT); //speaker
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LEDS on:
digitalWrite(ledPin4, HIGH);
tone(Sound, Tone_G); // Tone to play out of speaker. This Tone is G
delay(200);
digitalWrite(ledPin3, HIGH);
tone(Sound, Tone_A); // Tone to play out of speaker. This Tone is G
delay(200);
digitalWrite(ledPin2, HIGH);
tone(Sound, Tone_B); // Tone to play out of speaker. This Tone is G
delay(200);
noTone(Sound);
}
else {
// turn LEDS off:
digitalWrite(ledPin2, LOW);
delay(100);
digitalWrite(ledPin3, LOW);
delay(100);
digitalWrite(ledPin4, LOW);
delay(100);
}
}