Boboter
Loading...
Searching...
No Matches
buzzer.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <hal/ledc_types.h>
11#include <soc/gpio_num.h>
12#include "include/log_sources.h"
13
14class Robot;
15
16namespace Device {
17 class Buzzer {
18 private:
19 static constexpr const char* TAG = "Device::Buzzer";
20 static constexpr log_source LOG_SOURCE = LOG_SOURCE_DEVICE_BUZZER;
21
22 static constexpr gpio_num_t BUZZER_PIN = GPIO_NUM_19;
23 static constexpr ledc_timer_t LEDC_TIMER = LEDC_TIMER_1;
24 static constexpr ledc_channel_t LEDC_CHANNEL = LEDC_CHANNEL_2;
25
26 static constexpr uint16_t INITIAL_FREQUENCY = 100;
27 static constexpr uint16_t DUTY_CYCLE = 256;
28
29 static constexpr uint16_t FREQUENCY_MIN = 20;
30 static constexpr uint16_t FREQUENCY_MAX = 15'000;
31
32 Robot& robot;
33 uint16_t current_frequency;
34 bool turned_off;
35
36 public:
37 explicit Buzzer(Robot& robot);
38 ~Buzzer();
39
43 void initialize();
44
50 void set_frequency(uint16_t frequency);
51
55 void turn_off();
56 };
57}
void initialize()
Sets up the necessary GPIO pin and LEDC channel.
Definition buzzer.cpp:26
~Buzzer()
Definition buzzer.cpp:21
void set_frequency(uint16_t frequency)
Set buzzer to a given frequency.
Definition buzzer.cpp:54
void turn_off()
Stops buzzer output until it's set again.
Definition buzzer.cpp:78
Buzzer(Robot &robot)
Definition buzzer.cpp:13
Class containing all the components of the robot.
Definition robot.h:32
log_source
Definition log_sources.h:12
@ LOG_SOURCE_DEVICE_BUZZER
Definition log_sources.h:23
Definition battery.cpp:14