EasyManua.ls Logo

Freenove ESP32 - Page 96

Default Icon
159 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Need support? support@freenove.com
94
Chapter 8 Buzzer
www.freenove.com
The following is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void setup() {
setupBuzzer();
for (int i = 0; i < 3; i++) {
setBuzzer(1000);
delay(100);
setBuzzer(0);
delay(100);
}
delay(3000);
setMelodyToPlay(MELODY_POWER_UP);
}
void loop() {
delay(1000);
}
Initialize the buzzer pin.
2
setupBuzzer();
Control the passive buzzer to emit a sound at specific frequency.
4
setBuzzer(1000);
Each time this function is called, a thread will be created and a melody will be played. The thread will be closed
after playback is complete.
10
setMelodyToPlay(MELODY_POWER_UP);
Buzzer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef _BUZZER_h
#define _BUZZER_h
#include "NoteFrequency.h"
#include "Arduino.h"
#define MELODY_POWER_UP 0
#define MELODY_LOW_POWER 1
#define MELODY_NO_POWER 2
#define MELODY_WIFI_CONNECT_SUCCESS 3
#define MELODY_WIFI_CONNECT_FAILED 4
#define MELODY_WIFI_DISCONNECT 5
#define MELODY_BLE_CONNECT_SUCCESS 6
#define MELODY_BLE_DISCONNECT 7
#define MELODY_CAM_CONNECT_SUCCESS 8
#define MELODY_CAM_DISCONNECT 9
#define MELODY_CAM_FAILURE 10
#define MELODY_BEEP_1 11
#define MELODY_BEEP_2 12

Related product manuals