Hi, I have an excellent sketch for setting turn on times of the mains AC voltage or what is known technically as phase control. I am using a random phase optocoupler and triac to vary the brightness of a 240vac filament globe. There is no flicker at all in the globe. The controlled device could just as easily be any mains operated device.
I have attached a copy of the sketch (program). Now I need to exit the loop every say 1 minute to read an analog voltage. This analog voltage automatically sets the delay times. Can anybody provide me with the programming to do this? It will probably involve a goto statement to go to that part of the sketch which reads the analog voltage. The reading of this voltage would be so fast at computer speeds that the phase control would not noticeably be affected.
Can the programming needed be as simple as possible. Everybody likes simplicity.
Sorry couldn't upload file. Not allowed file extension. So here it is;
bool state=LOW;
int pin=7; // this pin connects to zero crossing detector circuit
int ledPin = 8; // pin 8 connects to random phase opto
void setup() {
Serial.begin(9600);
pinMode(pin,INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if(digitalRead(pin)==HIGH && state==LOW){ //rising edge detection
Serial.println(5); //picks up rising edge but not falling edge
digitalWrite(ledPin,LOW);
delayMicroseconds (4500);
digitalWrite(ledPin,HIGH);
delayMicroseconds (4500);
digitalWrite(ledPin,LOW);
}
}
I have attached a copy of the sketch (program). Now I need to exit the loop every say 1 minute to read an analog voltage. This analog voltage automatically sets the delay times. Can anybody provide me with the programming to do this? It will probably involve a goto statement to go to that part of the sketch which reads the analog voltage. The reading of this voltage would be so fast at computer speeds that the phase control would not noticeably be affected.
Can the programming needed be as simple as possible. Everybody likes simplicity.
Sorry couldn't upload file. Not allowed file extension. So here it is;
bool state=LOW;
int pin=7; // this pin connects to zero crossing detector circuit
int ledPin = 8; // pin 8 connects to random phase opto
void setup() {
Serial.begin(9600);
pinMode(pin,INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if(digitalRead(pin)==HIGH && state==LOW){ //rising edge detection
Serial.println(5); //picks up rising edge but not falling edge
digitalWrite(ledPin,LOW);
delayMicroseconds (4500);
digitalWrite(ledPin,HIGH);
delayMicroseconds (4500);
digitalWrite(ledPin,LOW);
}
}
