ESP_IOT
v2.5
IOT ESP Coding
BuzzerSensorClass.cpp
Go to the documentation of this file.
1
//
2
// BuzzerSensorClass.cpp
3
//
4
//
5
// Created by Scott Moody on 5/14/25.
6
//
7
8
9
#include "../../Defines.h"
10
11
#include "
BuzzerSensorClass.h
"
12
13
//! add here for now ..
14
//boolean _pinValid_BuzzerSensorClass = true;
15
16
17
BuzzerSensorClass::BuzzerSensorClass
(
char
*config) :
SensorClassType
(config)
18
{
19
20
SerialDebug.printf(
"BuzzerSensorClass init %s\n"
, config);
21
}
22
23
24
//!@see https://www.w3schools.com/cpp/cpp_class_methods.asp
25
void
BuzzerSensorClass::loop
()
26
{
27
if
(!
_pinsValid
)
28
return
;
29
}
30
31
32
void
BuzzerSensorClass::setup
()
33
{
34
SerialDebug.printf(
"BuzzerSensorClass::setup(%d,%d)\n"
,
_pin1
,
_pin2
);
35
#ifdef NO_HARD_WIRE
36
if
(
_pin1
== 0)
37
{
38
//! default to 21,33
39
//! BuzzerSensorClass,23,33
40
#ifdef ESP_M5_ATOM_S3
41
_pin1
= 39;
42
_pin2
= 38;
43
#else
44
_pin1
= 23;
45
_pin2
= 33;
46
#endif
47
}
48
#endif
49
50
51
_pinsValid
=
registerPinUse_mainModule
(
_pin1
,
"Pin1"
,
"BuzzerSensorClass"
,
false
);
52
_pinsValid
=
_pinsValid
&&
registerPinUse_mainModule
(
_pin2
,
"Pin2"
,
"BuzzerSensorClass"
,
false
);
53
if
(!
_pinsValid
)
54
{
55
SerialError.println(
"*** BuzzerSensorClass invalid Pins"
);
56
return
;
57
}
58
//! 7.14.26 try the power and pin, vs 2 pins
59
if
(
_pin1
== -1)
60
{
61
//! willl be the new PWR version
62
pinMode(
_pin2
, OUTPUT);
63
64
// Active-low buzzer (connected between 3.3V and GPIO21)
65
digitalWrite(
_pin2
, HIGH);
// OFF
66
}
67
else
68
{
69
//https://www.reddit.com/r/arduino/comments/1g89dlo/esp32_crashing_due_to_pinmode_and_fastled/
70
pinMode(
_pin1
, OUTPUT);
71
pinMode(
_pin2
, OUTPUT);
72
73
74
//! turn off..
75
digitalWrite(
_pin1
, LOW);
76
digitalWrite(
_pin2
, LOW);
77
}
78
79
SerialDebug.println(
"DONE BuzzerSensorClass::setup"
);
80
}
81
82
/**
83
** PIN_USE: Pin2 = 22, module=BuzzerSensorClass
84
** PIN_USE: RX = 22, module=ATOMQRCodeModule
85
** PIN_USE: TX = 19, module=ATOMQRCodeModule
86
** PIN_USE: DATA_PIN = 27, module=LED_DisPlay::begin
87
** PIN_USE: KEY_PIN = 32, module=KeyUnitSensorClass
88
** PIN_USE: DATA_PIN = 26, module=KeyUnitSensorClass
89
** PIN_USE: FastLED = 26, module=KeyUnitSensorClass
90
** PIN_USE: IN1_PIN = 21, module=L9110S_DCStepperClass
91
** PIN_USE: IN2_PIN = 25, module=L9110S_DCStepperClass
92
*/
93
94
//! local code
95
//! if using the GROVE, the right 2 pins would be 26, 32
96
void
BuzzerSensorClass::performBuzzer()
97
{
98
if
(!
_pinsValid
)
99
return
;
100
//! 7.15.26 -- Adding a -1 pin which means the other pin is the PWR
101
SerialDebug.printf(
"BuzzerSensorClass::performBuzzer(pin1=%d,pin2=%d)\n"
,
_pin1
,
_pin2
);
102
if
(
_pin1
== -1)
103
{
104
// Turn buzzer ON
105
digitalWrite(
_pin2
, LOW);
106
delay(100);
107
// Turn buzzer OFF
108
digitalWrite(
_pin2
, HIGH);
109
}
110
else
111
{
112
digitalWrite(
_pin1
, HIGH);
113
digitalWrite(
_pin2
, LOW);
114
delay(100);
115
digitalWrite(
_pin1
, LOW);
116
digitalWrite(
_pin2
, LOW);
117
}
118
}
119
120
//! 5.15.25 try a special command local to this class
121
void
BuzzerSensorClass::messageLocal_SensorClassType
(
char
*message)
122
{
123
SerialDebug.printf(
"BuzzerSensorClass::messageLocal_SensorClassType(%s)\n"
, message);
124
if
(strcmp(message,
"click"
)==0)
125
{
126
SerialDebug.println(
"BuzzerSensorClass.click"
);
127
performBuzzer();
128
}
129
}
130
#ifdef NOT_DEFINED
131
132
133
//! adding the messages as well
134
//! 5.14.25 (Laura/Paul flying). 5.14.74 great Dead
135
//! 8.28.23 Adding a way for others to get informed on messages that arrive
136
//! for the set,val
137
//! 12.27.23 support setName == "socket"
138
//! 1.10.24 if deviceNameSpecified then this matches this device, otherwise for all.
139
//! It's up to the receiver to decide if it has to be specified
140
void
BuzzerSensorClass::messageSetVal_SensorClassType
(
char
*setName,
char
* valValue,
boolean
deviceNameSpecified)
141
{
142
143
}
144
145
//! 12.28.23, 8.28.23 Adding a way for others to get informed on messages that arrive
146
//! for the send -
147
void
BuzzerSensorClass::messageSend_SensorClassType
(
char
*sendValue)
148
{
149
150
}
151
152
//! 12.28.23, 8.28.23 Adding a way for others to get informed on messages that arrive
153
//! for the cmd
154
void
BuzzerSensorClass::messageCmd_SensorClassType
(
char
*cmdValue)
155
{
156
157
}
158
#endif
//NOT_DEFINED
BuzzerSensorClass.h
registerPinUse_mainModule
boolean registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)
Definition:
MainModule.cpp:4340
BuzzerSensorClass::messageLocal_SensorClassType
void messageLocal_SensorClassType(char *message)
these are not initialized...
Definition:
BuzzerSensorClass.cpp:121
BuzzerSensorClass::setup
void setup()
Pure Virtual Function.
Definition:
BuzzerSensorClass.cpp:32
BuzzerSensorClass::loop
void loop()
Pure Virtual Function.
Definition:
BuzzerSensorClass.cpp:25
BuzzerSensorClass::BuzzerSensorClass
BuzzerSensorClass(char *config)
constructor
Definition:
BuzzerSensorClass.cpp:17
SensorClassType
Definition:
SensorClassType.h:26
SensorClassType::messageCmd_SensorClassType
virtual void messageCmd_SensorClassType(char *cmdValue)
Definition:
SensorClassType.h:106
SensorClassType::_pin1
int _pin1
Definition:
SensorClassType.h:113
SensorClassType::_pinsValid
boolean _pinsValid
12.19.25 add ability to know which kind of SensorClass we are
Definition:
SensorClassType.h:121
SensorClassType::_pin2
int _pin2
pin2
Definition:
SensorClassType.h:115
SensorClassType::messageSend_SensorClassType
virtual void messageSend_SensorClassType(char *sendValue)
Definition:
SensorClassType.h:102
SensorClassType::messageSetVal_SensorClassType
virtual void messageSetVal_SensorClassType(char *setName, char *valValue, boolean deviceNameSpecified)
Definition:
SensorClassType.h:98
src
SensorClass
BuzzerSensorClass.cpp
Generated on Wed Sep 23 2026 09:28:53 for ESP_IOT by
1.9.5