Hi all,
I am working on a very simple project that when you press a button a buzzer sounds until you let go of the button.
It is working well, but there is a slight delay from when you press the button and when the buzzer sounds, and there is about 1 seconds delay from when you let go of the the button and when the buzzer stops.
Code:
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 9; // the number of the pushbutton pin
int piezoPin = 8;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
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) {
tone(piezoPin, 1000);
}
if (buttonState == LOW) {
noTone (piezoPin);
}
}
Is it possible to get rid of these delays?
Thanks very much,
Zeb