我如何在 gpio 引脚上使用 pwm?有人帮帮我吗?有人分享简单的 pwm 示例吗?
ESP8266.com 版主
让派对开始并 +1
[url=https://www.banggood.com/custlink/KvGGhGF4wG[/url]
我喜欢 ESP8266 和 ESP8285 和 ESP32
Code:
Select all#define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_GPIO2_U
#define PWM_0_OUT_IO_NUM 2
#define PWM_0_OUT_IO_FUNC FUNC_GPIO2
#define PWM_CHANNEL 1
Code:
Select alluint8_t duty=0;
pwm_init( 150, &duty);
pwm_start();
Code:
Select allpwm_set_duty(duty, 0);
pwm_start();
Code:
Select all#include
#include
#include
#include
#include \"user_interface.h\"
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
// see eagle_soc.h for these defini
tions
#define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_GPIO2_U
#define PWM_0_OUT_IO_NUM 2
#define PWM_0_OUT_IO_FUNC FUNC_GPIO2
#define PWM_CHANNEL 1
LOCAL uint8_t led_state=0;
LOCAL uint8_t duty=0;
//Main code function for heartbeat LED on GPIO2
void ICACHE_FLASH_ATTR
loop(os_event_t *events)
{
os_delay_us(10000);
led_state ? duty-- : duty++;
if (duty >= 255 ) led_state=1;
else if (duty <= 10 ) led_state=0;
pwm_set_duty(duty, 0);
pwm_start();
system_os_post(user_procTaskPrio, 0, 0 );
}
void user_init(void)
{
pwm_init( 150, &duty);
pwm_start();
//Start os task
system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
system_os_post(user_procTaskPrio, 0, 0 );
}