-
Notifications
You must be signed in to change notification settings - Fork 1
/
arduino-piano.ino
60 lines (49 loc) · 1.49 KB
/
arduino-piano.ino
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
59
60
#include "logger.hpp"
#include "keyboard.hpp"
#include "buzzer.hpp"
#include "recorder.hpp"
#include "player.hpp"
enum Pins : uint8_t {
ANALOG_KEYBOARD = A5,
DECREASE_OCTAVE_BUTTON = 8,
INCREASE_OCTAVE_BUTTON = 7,
RECORDER_BUTTON = 6,
PLAYBACK_BUTTON = 5,
PREVIOUS_MELODY_BUTTON = 4,
NEXT_MELODY_BUTTON = 3,
BUZZER = 2,
};
const Resistors resistors{ .R1 = 10000,
.R2 = 560,
.R3 = 1300,
.R4 = 2700,
.R5 = 3900,
.R6 = 5600,
.R7 = 7500,
.R8 = 10000 };
MelodyStorage melodyStorage;
Keyboard* keyboard{};
Buzzer* buzzer{};
Recorder* recorder{};
Player* player{};
void setup() {
log("Setup start");
keyboard = new Keyboard{ resistors,
Pins::ANALOG_KEYBOARD,
Pins::DECREASE_OCTAVE_BUTTON,
Pins::INCREASE_OCTAVE_BUTTON };
recorder = new Recorder{ Pins::RECORDER_BUTTON,
melodyStorage };
player = new Player{ Pins::PLAYBACK_BUTTON,
Pins::PREVIOUS_MELODY_BUTTON,
Pins::NEXT_MELODY_BUTTON,
melodyStorage };
buzzer = new Buzzer{ Pins::BUZZER };
log("Setup end");
}
void loop() {
keyboard->OnUpdate();
recorder->OnUpdate(*keyboard, *buzzer);
player->OnUpdate(*buzzer);
buzzer->Play(keyboard->GetNote(), keyboard->GetOctave());
}