-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_buzzer.cpp
More file actions
48 lines (37 loc) · 1.24 KB
/
test_buzzer.cpp
File metadata and controls
48 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ❌ THE OLD WAY (Blocking Audio & Ugly Math)
int buzzerPin = 8;
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Creating a "Success" double beep pattern freezes your code!
tone(buzzerPin, 1500); // Start low tone
delay(100); // ⚠️ Blocking! Sensons can't read.
noTone(buzzerPin);
delay(50); // ⚠️ Blocking! WiFi can disconnect.
tone(buzzerPin, 2500); // High tone
delay(100); // ⚠️ Blocking!
noTone(buzzerPin);
delay(5000);
}
// ==========================================
// ✅ THE INTEGRALL WAY (Non-Blocking Audio Patterns)
#define INTEGRALL_ENABLE_BUZZER
#include <Integrall.h>
Integrall::System integrall;
void setup() {
integrall.begin();
// 1. Initialize buzzer on pin 8
integrall.enableBuzzer(8);
// 2. Play a pre-built melodic success tone instantly in the background!
integrall.buzzerSuccess();
}
void loop() {
// 3. You can trigger custom, non-blocking audio patterns easily:
if (/* Error Condition */ false) {
// Beep 3 times, 150ms ON, 100ms OFF, at 2000Hz. Zero delay() calls!
integrall.buzzerPattern(3, 150, 100, 2000);
}
// The background engine calculates the tone timing and plays the melody! 🎵
integrall.handle();
}