-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBGMusic.h
55 lines (45 loc) · 1.1 KB
/
BGMusic.h
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
49
50
51
52
53
54
55
/*
BGMusic.h - Background Music player using tone() for Arduino UNO R4
Copyright (c) 2024 embedded-kiddie All Rights Reserved.
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/
#ifndef BGMUSIC_H
#define BGMUSIC_H
#include "Arduino.h"
#include "CBTimer.h"
#ifndef debug_begin
#define debug_begin(...)
#endif
#ifndef debug_print
#define debug_print(...)
#endif
#ifndef debug_println
#define debug_println(...)
#endif
// Music score
typedef struct {
int pin;
const int *notes;
const int *notes_bigin;
const int *notes_end;
int wholenote;
int loop;
} MusicScore_t;
class BGMusic {
private:
static MusicScore_t score;
static void music_callback(void);
static int (*duration_function)(int duration);
public:
BGMusic();
~BGMusic();
bool begin(int pin, const int notes[], int n_notes, int tempo, bool loop = false, bool start = false);
static bool start(void);
static bool stop(void);
void end(void);
void set_duration_function(int (*calc_duration_function)(int duration)) {
duration_function = calc_duration_function;
}
};
#endif