Devices & Components
Arduino Uno Rev3
Switch Actuator, APEM A01 series Illuminated Push-Button Switches
Jumper wires (generic)
Hardware & Tools
Soldering iron (generic)
Software & Tools
loopMidi
Hairless MIDISerial Bridge
Ableton Live 10 Trial
Project description
Code
MidiDrumPad.ino
arduino
1#include "Buttons.h" 2 3//------Notes------------- 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 // Button is pressed 54 if (state == 0) 55 { 56 midiNoteOn(Buttons[i]->Note,127); 57 } 58 59 // Button is not pressed 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// Send MIDI note ON 76void midiNoteOn(byte note, byte midiVelocity) 77{ 78 Serial.write(NOTE_ON_CMD); 79 Serial.write(note); 80 Serial.write(midiVelocity); 81} 82 83//Send MIDI note OFF 84void midiNoteOff(byte note, byte midiVelocity) 85{ 86 Serial.write(NOTE_OFF_CMD); 87 Serial.write(note); 88 Serial.write(midiVelocity); 89}
Buttons.h
arduino
1#ifndef Buttons_h 2#define Buttons_h 3 4#include <Arduino.h> 5 6//Button (Pin Number, Note Number) 7class Button 8{ 9 public: 10 Button(int pin, short note); 11 int getButtonState(); 12 int Note; 13 14 private: 15 int _pin; 16 short _note; 17 int _state; 18 int _lastState; 19}; 20 21#endif
You can download code from my Github
MidiDrumPad.ino
arduino
1#include "Buttons.h" 2 3//------Notes------------- 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 // Button is pressed 54 if (state == 0) 55 { 56 midiNoteOn(Buttons[i]->Note,127); 57 } 58 59 // Button is not pressed 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// Send MIDI note ON 76void midiNoteOn(byte note, byte midiVelocity) 77{ 78 Serial.write(NOTE_ON_CMD); 79 Serial.write(note); 80 Serial.write(midiVelocity); 81} 82 83//Send MIDI note OFF 84void midiNoteOff(byte note, byte midiVelocity) 85{ 86 Serial.write(NOTE_OFF_CMD); 87 Serial.write(note); 88 Serial.write(midiVelocity); 89}
You can download code from my Github
Buttons.h
arduino
1#ifndef Buttons_h 2#define Buttons_h 3 4#include <Arduino.h> 5 6//Button (Pin Number, Note Number) 7class Button 8{ 9 public: 10 Button(int pin, short note); 11 int getButtonState(); 12 int Note; 13 14 private: 15 int _pin; 16 short _note; 17 int _state; 18 int _lastState; 19}; 20 21#endif
Buttons.cpp
arduino
1#include "Buttons.h" 2 3 4Button::Button(int pin, short note) 5{ 6 _pin = pin; 7 pinMode(_pin, INPUT_PULLUP); 8 _state = 1; 9 _lastState = 1; 10 Note = note; 11} 12 13 14int Button::getButtonState() 15{ 16 int returnValue = -1; 17 int state = digitalRead(_pin); 18 19 if(state == _lastState) 20 return 5; 21 if(state!= _lastState) 22 { 23 if(state == 0) 24 { 25 returnValue = 0; 26 } 27 else 28 { 29 returnValue = 1; 30 } 31 } 32 33 _lastState = state; 34 35 return returnValue; 36}
Downloadable files
Unopad circuit - without LED
Unopad circuit - without LED

Unopad circuit - without LED
Unopad circuit - without LED

Comments
Only logged in users can leave comments