I have some really simple code and tested on an 8 MHz ATtiny85 and ATtiny2313. It's basically a blocking blink:
int relayPin = 7;
long offPeriod = 1 * 60 * 1000;
long onPeriod = 1 * 60 * 1000;
void setup()
{
pinMode(relayPin, OUTPUT);
}
void loop()
{
digitalWrite(relayPin, LOW);
delay(onPeriod);
digitalWrite(relayPin, HIGH);
delay(offPeriod);
}
When I assign onPeriod
and offPeriod
to be 1 * 1000
(1 second), the LED will blink as expected. When I add the 60 second multiplier in, it seems to fail.
For the ATtiny85 I use Arduino Pin 4 (physical pin 3) and for the ATtiny2313, I use Arduino pin 7 (physical pin 9).
I program through the Arduino IDE using boards manager to install the ATTinyCore library for the ATtiny2313 and this for the ATtiny85.
Am I doing something wrong here?
It looks like if I throw the delay in a function, and then invoke it with however many seconds I want, it will work. This is not good as it remains blocking. So perhaps the correct way to do this is to grab timestamps. Here's the somewhat working code:
int relayPin = 4;
unsigned long offPeriod = 60;
unsigned long onPeriod = 60;
void setup()
{
pinMode(relayPin, OUTPUT);
}
void loop()
{
digitalWrite(relayPin, LOW);
delaySeconds(onPeriod);
digitalWrite(relayPin, HIGH);
delaySeconds(offPeriod);
}
void delaySeconds(int s) {
for (int i = 0; i < s; i++) {
delay(1000);
}
}
unsigned long
and it doesn't work. Let me try throwing a delay(1000) in a function.15 * 60 * 1000 = 900000
I require.