Don't use delay() to manage the timing because then the timing gets confused with the IR function. Have a look at how millis() is used to manage timing without blocking in Several things at a time.
And just use an LED interval of 1 second so that you can verify it easily against your watch.
Correct, but the led is blinking at ~1 second interval.
Robin2:
Don't use delay() to manage the timing because then the timing gets confused with the IR function. Have a look at how millis() is used to manage timing without blocking in Several things at a time.
And just use an LED interval of 1 second so that you can verify it easily against your watch.
Ok , so here's what I did now. I copied the blink without delay example code into this sketch and made some observations. If I do not use the ir.send code then the led blinks at the correct interval of 1 second.
If I use that line of code then the timer goes wrong like it happened before.
I'm posting my code here.
#include <IRremote.h>
#define F_CPU 8000000
#define __AVR_ATtiny85__
#define PanasonicAddress 0x4004 // Panasonic address (Pre data)
#define PanasonicVolumeDown 0x1008485 // Panasonic Volume Down button
IRsend irsend; // Fixed output pin for IR LED on ATtiny85 is 1
const int ledPin = 4;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if (ledState == LOW)
{
ledState = HIGH;
irsend.sendPanasonic(PanasonicAddress, PanasonicVolumeDown); //This line is what causes timing issues
}
else
{
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
}
If I remove irsend.sendPanasonic(PanasonicAddress, PanasonicVolumeDown); line of code then the blink works without any issues.
If I don't then the timing is no longer correct and led blinks super fast. I tried changing const long interval = to 5000; (Five thousand)and now the led blinks at almost 1 second interval. Not exactly 1 second but close.
Also when I changed interval to 5000 then ATtiny takes like 10 to 15 seconds to reach the loop function after uploading the code.