Can you add a little code to toggle the on board LED after every delay and ( A ) check the time against the flashing LED and ( B ) comment out the calls to myTone() and myNoTone() and see does that restore the delay() to its proper duration?
I connected a LED to pin 6 of the attiny (PB1) and tried the following sketch:
#include <avr/delay.h>
void setup()
{
DDRB = (1 << PORTB0) | (1 << PORTB1);
PORTB = 0;
}
void loop()
{
myTone(500);
PORTB ^= (1 << PORTB1);
delay(1000);
myNoTone();
PORTB ^= (1 << PORTB1);
delay(1000);
}
ISR(TIMER1_COMPA_vect)
{
PORTB ^= (1 << PORTB0);
}
void myTone(int freq)
{
float period = 1.00/(float)freq;
float ticks = (125000.00*(float)period)/2.00;
int over = ticks/255;
TCCR1 = (1 << CTC1) | (1 << CS12); // divide by 8 prescaler
OCR1A = ticks; //
OCR1C = ticks; //
TIMSK = (1 << OCIE1A) | (1<<TOIE1);
sei();
}
void myNoTone()
{
TCCR1 = 0;
TCNT1 = 0;
}
the delays were still less than 1000ms, when I removed the tone functions the delays were normal.
Probably the interrupts are messing up with the delay()?