I want the buzzer every second for about 1/4 second (not continuous). I have a sketch thanks to arlo777 based on using millis() . It is a great sketch but I have one running on an Uno now that uses something close to what I have below but I dabbled with my code and can't recreate it. My wife finds the timing device very useful in counting during exercise. It buzzes when toggle is pushed and released and turns off on next toggle push and release.
// This is a sketch to help keep track of exercise when exercising. Many of the activities are based on holding something for so many seconds
// or counting so many reps. This will make the Arduino Uno send an activate signal to a buzzer every second.
int buzzerPin =11;
int buzzerState = 0;
int buttonPin = 6;
int buttonOld = 1;
int buttonNew;
int dt = 100;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buzzerPin,OUTPUT);
pinMode(buttonPin,INPUT_PULLUP);
}
void loop() {
buttonNew = digitalRead(buttonPin);
Serial.println(buttonNew);
delay(dt);
if((buttonOld == 1) && (buttonNew == 0)){
if (buzzerState == 0){
digitalWrite(13,HIGH);
tone(buzzerPin,440);
delay(90);
buzzerState = 1;}
else{
digitalWrite(13,LOW);
buzzerState = 0;
noTone(buzzerPin);
}}
buttonOld = buttonNew;
delay(dt);
}