Arduino 交流调光器代码灯泡在闪烁前不发光
我的代码有问题。。。我使用的是带有arduino的交流调光模块,我想让灯亮5秒钟,然后闪烁两次,然后重复Arduino 交流调光器代码灯泡在闪烁前不发光,arduino,microcontroller,arduino-c++,Arduino,Microcontroller,Arduino C++,我的代码有问题。。。我使用的是带有arduino的交流调光模块,我想让灯亮5秒钟,然后闪烁两次,然后重复 int AC_LOAD = 3; // Output to Opto Triac pin int dimming = 128; // Dimming level (0-128) 0 = ON, 128 = OFF void setup() { pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output attachInter
int AC_LOAD = 3; // Output to Opto Triac pin
int dimming = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
void setup()
{
pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}
//the interrupt function must take no parameters and return nothing
void zero_crosss_int() //function to be fired at the zero crossing to dim the light
{
// Firing angle calculation : 1 full 50Hz wave =1/50=20ms
// Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
// For 60Hz => 8.33ms (10.000/120)
// 10ms=10000us
// (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
int dimtime = (75*dimming); // For 60Hz =>65
delayMicroseconds(dimtime); // Wait till firing the TRIAC
digitalWrite(AC_LOAD, HIGH); // Fire the TRIAC
delayMicroseconds(10); // triac On propogation delay
// (for 60Hz use 8.33) Some Triacs need a longer period
digitalWrite(AC_LOAD, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}
void loop()
{
{
int e = 5;
dimming = e;
delay(200);
}
{
for (int i=128; i >= 5; i--){
dimming=i;
delay(2);
}
for (int j=5; j <= 128; j++){
dimming=j;
delay(2); // this value is the light delay timing
}
//delay(3); // this value is the gap timing
for (int i=128; i >= 5; i--){
dimming=i;
delay(2);
}
for (int j=5; j <= 128; j++){
dimming=j;
delay(2); // this value is the light delay timing
}
//delay(3); // this value is the gap timing
}}
但如果我只使用代码的这一部分和下面的代码。它发光
我对编程非常陌生,请帮我解决一下您观察到的5秒延迟是Arduino的启动时间。Arduinos引导程序将在执行草图之前等待新的固件软件 如果您想让灯亮5秒钟,请更换
delay(200)代码>通过延迟(5000)代码>delay()在循环()中没有毫秒。您正在变暗
中写入大量数字。您的编译器可能会优化掉一些写访问,因为——正如编译器所知——没有从变量中读取任何内容。尝试将暗显
声明为易失性
,这样每一个更改都会被写入,并且可以被ISR看到。
{
int e = 5;
dimming = e;
delay(200);
}