27 lines
569 B
C
27 lines
569 B
C
#include "driver/gpio.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_rom_sys.h"
|
|
|
|
#define BUZ_GPIO GPIO_NUM_19
|
|
|
|
void buzzer_init(void)
|
|
{
|
|
gpio_reset_pin(BUZ_GPIO);
|
|
gpio_set_direction(BUZ_GPIO, GPIO_MODE_OUTPUT);
|
|
}
|
|
|
|
void buzzer_beep(uint32_t ms)
|
|
{
|
|
const int period_us = 500; // ~2 kHz
|
|
|
|
int cycles = (ms * 1000) / period_us;
|
|
|
|
for (int i = 0; i < cycles; i++) {
|
|
gpio_set_level(BUZ_GPIO, 1);
|
|
esp_rom_delay_us(period_us / 2);
|
|
gpio_set_level(BUZ_GPIO, 0);
|
|
esp_rom_delay_us(period_us / 2);
|
|
}
|
|
}
|