I want to control an AC load such that it powers on for 1 minute, then turns off for 1 hour, then on again for 1 min, and so on, in a loop.
I just modified the blink sketch to do:
- Turn
A1
on - Then delay for 60,000 ms
- Then turn
A1
off - Then delay for 3,600,000 ms (3,600 sec, or 1 hour)
...but it doesn't seem to work.
It looks like the LED connected to A0
turns on but instead of turning off after 1 min, it turns off after 8 min 30 s.
Any suggestions?
I rectified the sketch. Now it takes 1 sec as actual 1 sec. I chose 1 MHz clock in IDE.
int ledPin = A3; // the number of the LED pin
int ledState = HIGH; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long OnTime = 60000; // milliseconds of on-time
unsigned long OffTime = 10000; // milliseconds of off-time
void setup()
{
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
}
Then it turns on for 1 sec and then turns off for 1 sec, then randomly turns on at 30 sec or 1 min 30 sec. I want to turn it on for 1 min every hour.
I tried the Blink sketch modified as follows:
void setup() {
pinMode(A3, OUTPUT);
}
void loop() {
digitalWrite(A3, HIGH);
delay(60000);
digitalWrite(A3, LOW);
delay(900000);
}
But it still turns on for 1 min and turns off for 1 min.
I also tried this:
void setup() {
pinMode(A3, OUTPUT);
}
void loop() {
digitalWrite(A3, HIGH);
delay(60000);
digitalWrite(A3, LOW);
delay(3.6e+6);
}
No matter what I do on time and off time, it always remains the same.
I wanted to know one thing: can I set a 1-hour off and 1-min on timer using ATtiny13A or not?
I tried 1.2 MHz, 1 MHz, all clocks in the IDE, nothing seems to work.