In Attiny85 delay is not working in arduino IDE

I am using Attiny 85 with the 8MHz internal clock in Arduino IDE, I am also using RFreceiver SRX 882with the same device. I have an issue that delay is not working in this code. when the delay is encountered in any condition then my code stuck into its last condition.

Code

#include <avr/io.h>

#include <VirtualWire.h>

#define led1_pin 0
#define led2_pin 1
#define led3_pin A2
#define led4_pin A3
#define receive_pin A1
#define DeviceID 4
#define REset 100

void setup() {
pinMode(led1_pin, OUTPUT); pinMode(led2_pin, OUTPUT); pinMode(led3_pin, OUTPUT); pinMode(led4_pin, OUTPUT);
digitalWrite(led1_pin, LOW); digitalWrite(led2_pin, LOW); digitalWrite(led3_pin, LOW); digitalWrite(led4_pin, LOW);
vw_set_rx_pin(receive_pin);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_rx_start();

}

void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
if(buf[0] == DeviceID)
{
digitalWrite(led1_pin, HIGH); digitalWrite(led2_pin, HIGH); digitalWrite(led3_pin, HIGH); digitalWrite(led4_pin, HIGH);
delay(2000);
digitalWrite(led1_pin, LOW); digitalWrite(led2_pin, LOW); digitalWrite(led3_pin, LOW); digitalWrite(led4_pin, LOW);
delay(2000);
digitalWrite(led1_pin, HIGH); digitalWrite(led2_pin, HIGH); digitalWrite(led3_pin, HIGH); digitalWrite(led4_pin, HIGH);
delay(2000);
}
else if(buf[0] == REset)
{
digitalWrite(led1_pin, LOW); digitalWrite(led2_pin, LOW); digitalWrite(led3_pin, LOW); digitalWrite(led4_pin, LOW);
}
}
}

So anyone has an idea of why a delay is not working hereā€¦

I am using Attiny 85 with the 8MHz internal clock in Arduino IDE

You may be programming it using the IDE, but you are not USING it in the IDE.

So anyone has an idea of why a delay is not working here...

Some proof that it isn't working, and some definition of working, would definitely be in order.

You may be programming it using the IDE, but you are not using it in the IDE.

I am using it in IDE

Utsav13:
I am using it in IDE

That does not make sense. The hardware can not be "used" in the Interactive Design Environment.

That does not make sense. The hardware can not be "used" in the Interactive Design Environment.

yes, the hardware is not IDE
but my issue is that attiny85 is not generating delay as I declared in Arduino IDE software,
If I am run simple blinking code of led than delay works fine...
but why it is not generating delay here in my this code.
So can you help me to slove it?

Thanks!

I'm guessing buf[0] never equals DeviceID, so the delay()s are never executed.

Utsav13: Use Serial.print() to write the value of buf[0] to the serial terminal so you can see its value.

I'm guessing buf[0] never equals DeviceID, so the delay()s are never executed.

buf[0] receives data from RF receiver, and its work fine, I already check it using Serial.print().

The issue is that Delay() is executed but it's not working. when delay() is executed in this code that time code stops working and remains into its last condition like when delay() is executed code goes into the infinite delay.

The delay() function depends on one of the timers of the AVR. It appears that VirtualWire also uses a timer. Since the ATtiny85 has a very limited number of timers, it appears that there may be a conflict. This could cause the delay() to hang indefinitely.

The delay() function depends on one of the timers of the AVR. It appears that VirtualWire also uses a timer. Since the ATtiny85 has a very limited number of timers, it appears that there may be a conflict. This could cause the delay() to hang indefinitely.

So there is another way to give an exact delay?

Using millis() for timing.