Dumb Dad needs homework help!!!!!!!

OK heres the jist… 4th grade son needs to do an “invention”. what does he want to do? I see you tinkering with stuff all the time…How about a timer that counts down when I’m playing video games and than shuts off the TV? WHOA, slow down. Let me do some research first.

Many days later…

How about we just do a countdown timer? Sounds super simple right?

Well here is where i need help. FAST (due tomorrow!!!)

I have a http://nootropicdesign.com/digitshield/

which is actually just a 4 digit 7 segment display with the transistors and time shifters built in on a protoshield board.

I can easily get a countdown timer going with no problem, But 2 things…

All i want to do is add:

  1. a piezo buzzer at zero that buzzs for no longer than like 3 or 5 seconds and
  2. a button or switch so that when it gets to zero will reset back to given a total seconds

not anything that changes time or pauses or anything

Right now all it does is loop from 300 seconds to zero than back to 300 to zero again and again and again.

Heres the code so far it already has the setup for the button and buzzer (I think)

I read all the tutorials on timer, tone, stopwatch, etc HELP!!!

#include <DigitShield.h>
float counter = 0;
int d = 10;
const int buttonPin = 8;     // the number of the pushbutton pin
const int speakerOut = 9;
int buttonState = 0;         // variable for reading the pushbutton status

#define BUTTON 8

void setup(){
  pinMode(buttonPin, INPUT);     
  pinMode(speakerOut, OUTPUT);


void loop() {
  counter = counter - .0001;

  if(counter <=0) {
    counter = 300;


can use a for loop for the soundmaker

Hi, can’t you just do this?

boolean wait_for_button_pressed = false; // this flag controls whether the loop waits for a buttonpress to restart the counter
  if (wait_for_button_pressed) // if true, a timeout expired, to restart must press a button
    if (digitalRead(buttonPin) == HIGH) // do something only if a button has been pressed
      counter = 300; // reset the counter to the initial value
      wait_for_button_pressed = false; // proceed normally until the counter goes to 0 again
  else // normal condition
    counter = counter - .0001;
    if(counter <=0) 
      tone(pin, frequency, duration); // with pin, frequency, duration to be defined
      wait_for_button_pressed = true; // set the flag so that next loops will check for buttonpress

I didn’t try it so it may contain errors. It is not very accurate and it may miss a button press if released really fast, but it’s simple and should work, quick. For the physical assignment of pins to buzzers and buttons refer to the library examples.