12345678910111213141516171819202122232425262728293031323334 |
- #include <Arduino.h>
- #include "buzzer.h"
- #define PIN_BUZZER 18
- #define PWM_CHANNEL_BUZZER 0
- #define RESOLUTION_BUZZER 8
- void buzzer_setup() {
- ledcSetup(PWM_CHANNEL_BUZZER, 2000, RESOLUTION_BUZZER);
- ledcAttachPin(PIN_BUZZER, PWM_CHANNEL_BUZZER);
- ledcWrite(PWM_CHANNEL_BUZZER, 128);
- }
- void buzz() {
- ledcWriteTone(PWM_CHANNEL_BUZZER, 300);
- delay(800);
- ledcWriteTone(PWM_CHANNEL_BUZZER, 0);
- }
- void beep() {
- ledcWriteTone(PWM_CHANNEL_BUZZER, 2000);
- delay(200);
- ledcWriteTone(PWM_CHANNEL_BUZZER, 0);
- }
- void test_buzzer() {
- for (int freq = 255; freq < 10000; freq = freq + 250){
- Serial.print("Testing frequency: "); Serial.println(freq);
-
- ledcWriteTone(PWM_CHANNEL_BUZZER, freq);
- delay(1000);
- }
- }
|