|
楼主 |
发表于 2020-9-3 03:24
|
显示全部楼层
是打错了pinMode,后面补回去就好了。
现在有个新问题,就是我照着代码加了几个led灯组,然后开始乱闪了,我贴代码给你看看~
#define WW_LED 2
#define WW_LED2 3
#define WW_LED3 6
#define WW_LED4 7
#define WW_ON 30
#define WW_OFF 180
#define WW_ON2 60
#define WW_OFF2 300
unsigned long FLASH_START_TIME = 0;
unsigned long FLASH_START_TIME2 = 0;
unsigned long FLASH_START_TIME3 = 180;
unsigned long FLASH_START_TIME4 = 300;
void setup(){
pinMode( WW_LED, OUTPUT );
pinMode( WW_LED2, OUTPUT );
pinMode( WW_LED3, OUTPUT );
pinMode( WW_LED4, OUTPUT );
}
void loop()
{
//.......................................................................... LED1
if ( millis()-FLASH_START_TIME <= WW_ON2 )
digitalWrite( WW_LED, HIGH );
else
{
if ( millis()-FLASH_START_TIME <= WW_ON2*2 )
digitalWrite( WW_LED, LOW );
else
{
if ( millis()-FLASH_START_TIME <= WW_ON2*3 )
digitalWrite( WW_LED, HIGH );
else
{
if ( millis()-FLASH_START_TIME <= WW_ON2*4 )
digitalWrite( WW_LED, LOW );
else
{
if ( millis()-FLASH_START_TIME <= WW_ON2*5 )
digitalWrite( WW_LED, HIGH );
else
{
if ( millis()-FLASH_START_TIME <= (WW_ON2*5+WW_OFF2) )
digitalWrite( WW_LED, LOW );
else
FLASH_START_TIME = millis();
}
//.......................................................................... LED2
{
if ( millis()-FLASH_START_TIME4 <= WW_ON2 )
digitalWrite( WW_LED2, HIGH );
else
{
if ( millis()-FLASH_START_TIME4 <= WW_ON2*2 )
digitalWrite( WW_LED2, LOW );
else
{
if ( millis()-FLASH_START_TIME4 <= WW_ON2*3 )
digitalWrite( WW_LED2, HIGH );
else
{
if ( millis()-FLASH_START_TIME4 <= WW_ON2*4 )
digitalWrite( WW_LED2, LOW );
else
{
if ( millis()-FLASH_START_TIME4 <= WW_ON2*5 )
digitalWrite( WW_LED2, HIGH );
else
{
if ( millis()-FLASH_START_TIME4 <= (WW_ON2*5+WW_OFF2 ))
digitalWrite( WW_LED2, LOW );
else
FLASH_START_TIME4 = millis();
}
///////////////////////////////////////////////////////////////
//.......................................................................... LED3
{ if ( millis()-FLASH_START_TIME2 <= WW_ON )
digitalWrite( WW_LED3, HIGH );
else
{
if ( millis()-FLASH_START_TIME2 <= WW_ON*2 )
digitalWrite( WW_LED3, LOW );
else
{
if ( millis()-FLASH_START_TIME2 <= WW_ON*3 )
digitalWrite( WW_LED3, HIGH );
else
{
if ( millis()-FLASH_START_TIME2 <= WW_ON*4 )
digitalWrite( WW_LED3, LOW );
else
{
if ( millis()-FLASH_START_TIME2 <= WW_ON*5 )
digitalWrite( WW_LED3, HIGH );
else
{
if ( millis()-FLASH_START_TIME2 <= (WW_ON*5+WW_OFF) )
digitalWrite( WW_LED3, LOW );
else
FLASH_START_TIME2 = millis();
}
//.......................................................................... LED4
{ if ( millis()-FLASH_START_TIME3 <= WW_ON )
digitalWrite( WW_LED4, HIGH );
else
{
if ( millis()-FLASH_START_TIME3 <= WW_ON*2 )
digitalWrite( WW_LED4, LOW );
else
{
if ( millis()-FLASH_START_TIME3 <= WW_ON*3 )
digitalWrite( WW_LED4, HIGH );
else
{
if ( millis()-FLASH_START_TIME3 <= WW_ON*4 )
digitalWrite( WW_LED4, LOW );
else
{
if ( millis()-FLASH_START_TIME3 <= WW_ON*5 )
digitalWrite( WW_LED4, HIGH );
else
{
if ( millis()-FLASH_START_TIME3 <= (WW_ON*5+WW_OFF) )
digitalWrite( WW_LED4, LOW );
else
FLASH_START_TIME3 = millis();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
1和2还是正常的,就后面3和4乱闪,我的理解是时间从0开始走,然后到标注点开始执行,正常应该是各做各的,现在看3和4是被干扰到的样子,。不知道是我理解错了,然后写错代码还是具体哪部分细节搞错了
|
|