1#include "Buttons.h"
2
3
4#define NOTE_ONE 36
5#define NOTE_TWO 37
6#define NOTE_THREE 38
7#define NOTE_FOUR 39
8#define NOTE_FIVE 40
9#define NOTE_SIX 41
10#define NOTE_SEVEN 42
11#define NOTE_EIGHT 43
12#define NOTE_NINE 44
13
14#define NOTE_ON_CMD 0x90
15#define NOTE_OFF_CMD 0x80
16#define MAX_MIDI_VELOCITY 127
17
18
19
20int NUMBER_BUTTONS = 9;
21
22Button Button1(4, NOTE_ONE);
23Button Button2(3, NOTE_TWO);
24Button Button3(2, NOTE_THREE);
25Button Button4(7, NOTE_FOUR);
26Button Button5(6, NOTE_FIVE);
27Button Button6(5, NOTE_SIX);
28Button Button7(10, NOTE_SEVEN);
29Button Button8(9, NOTE_EIGHT);
30Button Button9(8, NOTE_NINE);
31
32Button *Buttons[] {&Button1,&Button2,&Button3,&Button4,&Button5,&Button6,&Button7,&Button8,&Button9};
33
34
35int red_light_pin= 11;
36int green_light_pin = 12;
37int blue_light_pin = 13;
38
39
40void setup() {
41 Serial.begin(9600);
42}
43
44void loop() {
45 if (NUMBER_BUTTONS != 0) updateButtons();
46}
47
48void updateButtons() {
49
50 for (int i = 0; i < NUMBER_BUTTONS; i++) {
51 int state = Buttons[i]->getButtonState();
52
53
54 if (state == 0)
55 {
56 midiNoteOn(Buttons[i]->Note,127);
57 }
58
59
60 if (state == 1)
61 {
62 midiNoteOff(Buttons[i]->Note,0);
63 }
64 }
65}
66
67
68void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
69 {
70 analogWrite(red_light_pin, red_light_value);
71 analogWrite(green_light_pin, green_light_value);
72 analogWrite(blue_light_pin, blue_light_value);
73}
74
75
76void midiNoteOn(byte note, byte midiVelocity)
77{
78 Serial.write(NOTE_ON_CMD);
79 Serial.write(note);
80 Serial.write(midiVelocity);
81}
82
83
84void midiNoteOff(byte note, byte midiVelocity)
85{
86 Serial.write(NOTE_OFF_CMD);
87 Serial.write(note);
88 Serial.write(midiVelocity);
89}