I used this but replace with arduino mega 2560, change D8 to D53, below is my sketch:
int mydelay = 0;
int myvalue=0;
int last_CH1_state = 0;
int firing_pin = 3;
int zero_cross = 53;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode (firing_pin,OUTPUT);
pinMode (zero_cross,INPUT);
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT0);
Serial.begin(9600);
while (! Serial);
Serial.println("Enter value to control");
}
void loop() {
if (Serial.available())
{
String ch = Serial.readString();
int dataIn = ch.toInt();
if (dataIn >= 0 || dataIn <= 1024)
{
myvalue = map(dataIn,0,1024,7200,10);
}
}
if (mydelay == 1)
{
delayMicroseconds(myvalue);
digitalWrite(firing_pin,HIGH);
delayMicroseconds(100);
digitalWrite(firing_pin,LOW);
mydelay=0;
}
}
ISR(PCINT0_vect){
if(PINB & B00000001){
if(last_CH1_state == 0){
mydelay=1;
}
}
else if(last_CH1_state == 1){
mydelay=1;
last_CH1_state = 0;
}
}
But It's doesn't working, the bulb not response anything when I change value to control AC. Any help really appriciated.