Timer with ac phase control

Hello guys,

Have a following code:

int angle = 0, time = 0, controltriac = 1;

void setup() {
	pinMode(controltriac, OUTPUT);
	digitalWrite(controltriac, LOW);
	attachInterrupt(0, zerocrossing, RISING);
}

void loop() {
	angle = 180;
	time = (angle * 8.33) / 180;	
}


void zerocrossing() {
	for (int i = 0; i < time; i++)
	{
		delay(2);
	}
	digitalWrite(controltriac, HIGH);
	delay(1);
	digitalWrite(controltriac, LOW);
}

Need control a output pin: shutdown pin for 10 minutes, wait 5 minutes and start again.

Have use ATTINY85, clock internal 8MHz at arduino ide.

Don't ever put delay() and other long lasting commands in your ISR, this has to be a as fast as possible as interrupts are off while you're in the ISR. All it has to do is set a flag that indicates the zero crossing has taken place, then let loop() take care of the real work.

Don't use delay() in your code - use millis() (or for your very short time maybe micros()) based timing. See the "several things at a time" sticky in this forum or the "blink without delay" example code on how this works.

yeah, I know can't do this within interrupt, but project is not critical

yeah, I know can't do this within interrupt, but project is not critical

Whether or not the project is critical, delay() will not halt your program within the ISR to create the clipped waveform.

the delay have blocked execution in main loop! i've searching for delay replacement.

digitalWrite(3, HIGH);
delay(5000);
digitalWrite(3, LOW);
delay(5000);

How to make this without delay and work properly?

tiagomega:
How to make this without delay and work properly?

See my reply #1.

OK