arduino - 交流调光器代码灯泡在闪烁前不发光
问题描述
我的代码有问题...我正在使用带有 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
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 秒然后闪烁。它会延迟 5 秒,然后闪烁
{
int e = 5;
dimming = e;
delay(200);
}
但如果我只使用这部分代码和下面的代码。它发光
我真的是编程新手,请帮帮我
解决方案
您观察到的 5 秒延迟是 Arduino 的启动时间。在执行您的草图之前,Arduinos 引导加载程序将等待新固件。
如果您想让灯亮 5 秒钟,请替换delay(200);
为delay(5000);
。
推荐阅读
- javascript - react js中的类型错误需要不是一个函数
- node.js - Axios/Fetch 没有在浏览器中设置 cookie
- python - 如何将多个初始化字符串添加到 append() 方法中
- c# - 除十进制数时转换溢出
- excel - VBA函数定义一个数组并找到它的最大值
- windows - INS-08101 在状态下执行操作时出现意外错误:“mtsDialog”
- nuxt.js - 为具有相同父文件夹的动态路由设置优先级
- eclipse - 关闭休眠日志控制台
- intellij-idea - 构建时 IntelliJ 错误的源值
- google-chrome - Datalist HTML 显示的值比预期的要多