用ESP8266的PWM功能,写了一个呼吸灯程序,为什么只执行一次(灯慢慢点亮,然后慢慢熄灭,然后就狂闪)
LOCAL os_timer_t os_timer;
LOCAL uint8 set_duty=0;
LOCAL uint8 m=1;
LOCAL uint8 n=1;
void delay_ms(uint16 x)
{
for(;x>0;x--)
{
os_delay_us(1000);
}
}
static void ESP8266_PWM_RUN(void)
{//static uint8 set_duty=0;
//static uint8 m=1;
//static uint8 n=1;
if (m==1)
{
if ( set_duty >= 100 )
{
m=0;
}
set_duty=set_duty+2;
}
else
{
if ( set_duty <= 0 )
{
m=1;
}
set_duty=set_duty-1;
}
pwm_set_duty(set_duty,0);
pwm_set_duty(set_duty,1);
pwm_set_duty(set_duty,2);
pwm_start();
}
static void PWM_Init(void)
{
uint32 io_info[3][3]={
{PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},
{PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM},
{PWM_2_OUT_IO_MUX,PWM_2_OUT_IO_FUNC,PWM_2_OUT_IO_NUM}
};
uint32 duty[3]= {0};
pwm_init(5000,duty,3,io_info);
os_timer_disarm(&os_timer);
os_timer_setfn(&os_timer,(os_timer_func_t*)(ESP8266_PWM_RUN),NULL);
os_timer_arm( &os_timer,50,1);
}
void user_init(void)
{
PWM_Init();
}