AVR: Using ATmega328 Timer1 to create a delay
void oneSecondDelay() {


that function's construct isn't terribly optimal. you could have easily made it take a parameter to determine the length of the delay, not to mention other issues.

A quick fix would be something like this - it still has issues but at least workable.

//create a user-specified delay
//dly-duration in timer ticks
//timer1 presummed running, running at 256:1 prescaler
void myDelay(uint16_t dly) {
   // Set the target value to 62499
   OCR1A = TCNT1 + dly - 1;     //0xF423;

   // Set prescaler to 256 and start the timer
   //TCCR1B |= (1 &lt;&lt; WGM12) | (1 &lt;&lt; CS12);
   TCCR1B = (TCCR1B &amp;~0x07) | (TMR1_PS256x &amp; 0x07); //set timer1 prescaler to 256:1

   // Waiting for the overflow event
   while ((TIFR1 &amp; (1 &lt;&lt;  OCF1A)) == 0) {

   }

   TIFR1 |= (1&lt;&lt;OCF1A);         //clear the flag

}


that piece of code in action when fed TMR1_PS100ms as a parameter:



the goal of writing any piece of code is so that you don't have to write it again. That way, anything you write is an investment, not an expense.