why did i need GP2 pushbutton?
when i need to press that button?
sorry i didnt understand...
ABSF WROTE:I use the cytron example for detecting a push button to poll the GP2 pulse. Not sure if the flow is correct.
// AC dimmer with zero-crossing detection
// First edition by Niels Oestergaard
// !!!!!!!! not verified !!!!!!!!!!!!!
// based on design Andrew Kilpatricks tutorial: http://www.andrewkilpatrick.org/blog/?page_id=445
//strategy for dimming part of the sketch:
//
// set counting interval to reach 255 in one half-period (50 hz = 10 millis pr. half-period / 60 Hz 8.3333333333333 pr. halft periode )
// set output to 0 - 255
// detect zero crossing (on interrupt pin)
// in interrupt rutine calculate time for turning on
// when millis reaching time, turn on for a short while
// turn output off to be sure not to trigger to early in next halfperiod
// interrupt 0 - (pin 2)
int dimmer1Pin = 10; //output to opto triac (MOC 3010/3020)
int ledPin = 13; //reserved for sanity check and visual feedback
volatile int freqAdjTime = 20; //set to 10 for 50 Hz, and 8 for 60 Hz
volatile long nextOnTime = 0; // variable for storing a time (in millis) for when to fire the output next
volatile int outputValue; // Varialble for storing the output value 0-255
//unsigned int inputValue; // Variable for storing input value (ie. a potentiometer)
long lastMillis; // for timing purposes
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
// sanity check
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
// end of sanity check
attachInterrupt(0, zero, RISING); //Attachment of zero crossing detection, which means the interrupt routine "zero"
//is called each 20 millis at digital pin 2.
}
void loop()
{
//
if (nextOnTime < millis()) { //is it time to set pin on?
digitalWrite(dimmer1Pin, HIGH); // then set it
delay(2); // wait a bit to be sure the triac is on
digitalWrite(dimmer1Pin, LOW); // turn of the trigger to be sure it is not trigger in the very beginning of next halfperiod
}
// A loop that slowly increases outputvalue
if (millis()-lastMillis > 250 ) { //increase output each fourth of a second
outputValue++; //increase outputvalue by one
//Check if max is reached
if (outputValue > 255) { // output = maximum
outputValue = 0; // set output to zero
}
}
}
void zero()
{
// set a volatile variable with the millis value + (the value of the desired output (0-255) multiplied by the freq adj time)
nextOnTime = millis() + (freqAdjTime * outputValue); //how long will this calculation take? too long to enable low output??
}
As for the person who asked you that - tell him/her that AC currents are very dangerous and dimmer circuits must be constructed with the supervision of another person.
Btw, can you advise him to find examples of these AC light dimmer online elsewhere? It is not very safe to design it by the hand if he/she has insufficient knowledge on Power Electronics.
It is because I don't want him to destroy himself/herself, his/her Arduino, and the optocoupler.
Users browsing this forum: No registered users and 21 guests