After my timer runs out i want my buzzer to buzz 5 times. Right now it buzzes once this is my code. What would i change to beep more than once
#include <LiquidCrystal.h>
const int
RS = 12,
EN = 11,
D4 = 5,
D5 = 4,
D6 = 3,
D7 = 2;
const int
pinActiveBeeper = 7; //whatever pin you're using for the active beeper
LiquidCrystal lcd( RS, EN, D4, D5, D6, D7 );
const unsigned long
culPeriod = 5ul*60ul*1000ul; //5 minutes x 60 seconds/min x 1000mS/second
//nice string generation for LCD and serial monitor
char
szStr[16];
//timer variables
// timeStart is set in setup() and marks the beginning of the countdown
// timeNow is updated each pass of the loop and used to check how much time (in milliseconds) has elapsed
unsigned long
timeNow,
timeStart;
void setup()
{
//set up the serial monitor
Serial.begin(9600);
//initialize the 16x2 LCD, clear it and print "Countdown" on the first line
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Countdown:");
pinMode( pinActiveBeeper, OUTPUT );
digitalWrite( pinActiveBeeper, LOW );
//get the time marking the beginning of the countdown
timeStart = millis();
}//setup
void loop()
{
//these "static" variables are used to know when to update the display
//basically, when one of the minutes, seconds or tenths changes, the display
//is updated and a message sent to the serial monitor
static unsigned long
lastminutes = 0,
lastseconds = 0,
lasttenths = 0;
//from the time remaining in milliseconds, calculate the "human readable" min/sec/tenths
unsigned long
minutes,
seconds,
tenths;
unsigned long
timeRemaining;
//get the millisecond count now
timeNow = millis();
//culPeriod is set to the number of milliseconds in 5 minutes (5 x 60 x 1000)
//if the difference between the time we started setup() and now is equal to
//or greater than that value the countdown is done
if( (timeNow-timeStart) < culPeriod )
{
//not there yet; calc the time remaining in milliseconds
timeRemaining = culPeriod - (timeNow - timeStart);
//conver to minutes, seconds and tenths of a second
minutes = timeRemaining / 60000ul;
seconds = (timeRemaining - (minutes * 60000ul))/1000ul;
tenths = (timeRemaining - (minutes * 60000ul) - (seconds * 1000ul)) / 100ul;
//if any of those digits has changed since the last pass, send the updated
//values to the LCD and serial monitor
if( (minutes != lastminutes) || (seconds != lastseconds) || (tenths != lasttenths) )
{
sprintf( szStr, "%lu:%02lu:%d", minutes, seconds, tenths );
Serial.println( szStr );
lcd.setCursor(0, 1);
lcd.print( szStr );
//update the last values with the current values
lastminutes = minutes;
lastseconds = seconds;
lasttenths = tenths;
}//if
}//if
else
{
//sound the active beeper (assumes a high on the pin turns it on) for 1-second
Serial.println( "Beep on" );
digitalWrite( pinActiveBeeper, HIGH );
//normally don't use delay but since the action right after this is to halt and catch fire, why not?
delay(1000);
Serial.println( "Beep off" );
digitalWrite( pinActiveBeeper, LOW );
//halt and wait for reset to re-do countdown
while(1);
}//else
}//loop