-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path6_jukebox_player.cpp
58 lines (48 loc) · 1.09 KB
/
6_jukebox_player.cpp
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
56
57
58
#include <Arduino.h>
#include <TonePlayer.h>
#include <RTTTL.h>
#include <BLDCSpeaker.h>
BLDCMotor motor1 = BLDCMotor(PB1, PB0, PA7, 15);
BLDCSpeaker speaker1 = BLDCSpeaker(&motor1, 1.5, 10, -12);
TonePlayer player;
const char *songs[] = {
RTTTL_PINK_PANTHER,
RTTTL_SIMPSONS,
RTTTL_USA,
RTTTL_SUPER_MARIO_BROS,
RTTTL_SUPER_MARIO_BROS_POLY,
RTTTL_WALES,
RTTTL_FRANCE,
RTTTL_CROATIA
};
int song_index = 0;
int song_count = sizeof(songs) / sizeof(char *);
void setup()
{
Serial.begin(115200);
delay(750);
Serial.println(F("** JUKEBOX PLAYER **"));
/* WARNING: ensure voltage_limit isn't too high - you could overheat motor or MOSFETS!! */
motor1.voltage_limit = 1.5;
motor1.init();
player.attachSpeaker(&speaker1);
Song *song = parseRTTL(songs[song_index]);
player.play(song);
}
void loop()
{
if (player.isPlaying())
{
player.loop();
}
else
{
Serial.println("\nFinished");
delay(2000);
song_index++;
if (song_index > song_count - 1)
song_index = 0;
Song *song = parseRTTL(songs[song_index]);
player.play(song);
}
}