delay(1000); has different delay time in portions of code at 8MHz

Hello everyone, I am working on a wireless motion sensor to alert me whenever someone approaches the house. I'm using those cheap little 433MHz modules with a Manchester encoding library that some of you may be familiar with. Here's the setup:

The receiver is running an attiny45 @ 8MHz. Upon startup, I'm using digital pin 1 to generate some tones to a little speaker. First, a 500KHz tone for 1 second using delay(1000);, then a 600KHz tone for 1 second using delay(1000);. That part works fine. The weird part is, in the loop() section, when the receiver receives the code "1010", it's supposed to light an LED, generate the 500 and 600 KHz tones for 1 second each, then turn the LED off. The only thing is, it's doing it really fast, as if that section of code is running at 8MHz but acting like it was programmed for 1MHz, if that makes sense? Here's the code for the receiver:

#include <MANCHESTER.h>

#define RxPin 4
const int localAlarmPin =  0;
//int ledState = 0;  //commented out, this was for a slightly different project

void setup() 
{ 
 MANCHESTER.SetRxPin(RxPin);
 MANCHESTER.SetTimeOut(1000);

pinMode(localAlarmPin, OUTPUT);
digitalWrite(localAlarmPin, HIGH);
delay(1000);
   tone(1, 500);
   delay(1000);
   noTone(1);
   delay(1000);
   tone(1, 600);
   delay(1000);
   noTone(1);
   delay(1000);
digitalWrite(localAlarmPin, LOW);
}

void loop() 
{
 unsigned int data = MANCHESTER.Receive();
if (data == 1010){
   digitalWrite(localAlarmPin, HIGH);
   tone(1, 500);
   delay(1000);
   noTone(1);
   delay(1000);
   tone(1, 600);
   delay(1000);
   noTone(1);
  // delay(5000);
   digitalWrite(localAlarmPin, LOW);
}

}

Here is the code for the transmitter, which I just have setup with a pushbutton to trigger the transmitter (still waiting on my PIR boards to come in). This attiny45 is also running at 8MHz, although I think it is supposed to run at 1MHz, but couldn't get it to work like that:

#include <MANCHESTER.h>

#define TxPin 4  //the digital pin to use to transmit data
unsigned int Tdata;  //the 16 bits to send
const int sensePin1 = 2;
const int TXLED = 1;
const int TXPowerTransistor = 0;
int sensePin1State;
//int sensePin2State;
int x;
int i;

void setup() 
{                
MANCHESTER.SetTxPin(TxPin);      // sets the digital pin as output default 4
pinMode(sensePin1, INPUT);
pinMode(TXLED, OUTPUT);
pinMode(TXPowerTransistor, OUTPUT);
digitalWrite(TXLED, HIGH);
digitalWrite(TXPowerTransistor, LOW);
delay(3000);
}

void loop() 
{
sensePin1State = digitalRead(sensePin1);
//sensePin2State = digitalRead(sensePin2);
if (sensePin1State == HIGH){
  digitalWrite(TXPowerTransistor, LOW);
  digitalWrite(TXLED, LOW);
}

if (sensePin1State == LOW){
 digitalWrite(TXPowerTransistor, HIGH);
 digitalWrite(TXLED, HIGH);

  Tdata = 1010;
//Now let's send the data 20 times and hope it gets to the receiver
//since these little TX-RX modules have really shitty dropout
  for (int i = 0; (i < 20); i += 1){
 MANCHESTER.Transmit(Tdata);
 delay(100);
   }
 
 }

}

Any suggestions would be greatly appreciated! :slight_smile:

Have you edited boards.txt to tell the Arduino IDE that the ATTiny is running at 8MHz?