MIDIパッドコントローラー
USB接続のMIDIパッドコントローラーを作成しました。
使い方
1.左のボリュームが音量です。
2.左のボリュームを0にしてパッドを長押しすると、パッドのノートNo.(音階)が変更できる設定モードになります。
3.設定モードで右のボリュームを回すとノートNo.(音階)を変更できます。
4.再度、左のボリュームを0にしてパッドを長押しすると設定が完了します。
MIDIパッドコントローラー
パッドの反応はなかなか良い感じです。
使用したパーツ
- DFRduino Pro Mini V1.3 (16M5V328)
- ボリューム抵抗(250kΩ) × 2個
- その他電気系以外は100円均一の材料
材料費は全部で2000〜2500円程度です。
ソースコード(Arduino)
#include <MIDI.h> #include <Bounce2.h> #include <FlexiTimer2.h> #define PIN_MAX 5 #define MODE_CHANGE_TIME 1000 typedef enum { E_MODE_PLAY = 0, E_MODE_SETUP } E_MODE; MIDI_CREATE_DEFAULT_INSTANCE(); E_MODE mode; Bounce bouncer[PIN_MAX]; int secer_pin[] = {2, 3, 4, 5, 6}; const int led_pin = 9; int note[] = {40, 42, 44, 45, 47}; int ch[] = {1, 1, 1, 1, 1}; boolean pin_status[PIN_MAX]; int vol = 100; int ctl_vol2 = 0; int ptch = 0; int active_pad = 0; int led_val = 0; int led_loop_count = 0; void setup() { MIDI.begin(1); Serial.begin(38400); for (int i = 0;i < PIN_MAX;i++) { pinMode(secer_pin[i], INPUT_PULLUP); bouncer[i] = Bounce(); bouncer[i].attach(secer_pin[i]); bouncer[i].interval(10); pin_status[i] = false; } pinMode(led_pin, OUTPUT); changeModePlay(); } void loop() { switch (mode) { case E_MODE_PLAY: padPlay(); break; case E_MODE_SETUP: padSetup(); break; } } void padSetup() { int vol_data = analogRead(0); vol = map(vol_data, 0, 1023, 0, 127); int vol2 = analogRead(1); vol2 = map(vol2, 0, 1023, 0, 120); if (vol2 != ctl_vol2) { ctl_vol2 = vol2; MIDI.sendNoteOff(note[active_pad], 0, ch[active_pad]); note[active_pad] = ctl_vol2; } for (int i = 0;i < PIN_MAX;i++) { bouncer[i].update(); if (0 <= i && i <= 4) { if ( (bouncer[i].read() == LOW) && (false == pin_status[i]) ) { MIDI.sendNoteOn(note[i] + ptch, vol, ch[i]); pin_status[i] = true; if (0 == vol) { FlexiTimer2::set(MODE_CHANGE_TIME, changeModePlay); FlexiTimer2::start(); } } if ( (bouncer[i].read() == HIGH) && (true == pin_status[i]) ) { MIDI.sendNoteOff(note[i] + ptch, 0, ch[i]); pin_status[i] = false; FlexiTimer2::stop(); } } } if (1000 < led_loop_count) { led_loop_count = 0; blinkLed(); } led_loop_count++; } void padPlay() { int vol_data = analogRead(0); vol = map(vol_data, 0, 1023, 0, 127); int vol2 = analogRead(1); vol2 = map(vol2, 0, 1023, 0, 127); if (vol2 != ctl_vol2) { ctl_vol2 = vol2; MIDI.sendControlChange(0, ctl_vol2, 1); } for (int i = 0;i < PIN_MAX;i++) { bouncer[i].update(); if (0 <= i && i <= 4) { if ( (bouncer[i].read() == LOW) && (false == pin_status[i]) ) { MIDI.sendNoteOn(note[i] + ptch, vol, ch[i]); pin_status[i] = true; active_pad = i; if (0 == vol) { FlexiTimer2::set(MODE_CHANGE_TIME, changeModeSetup); FlexiTimer2::start(); } } if ( (bouncer[i].read() == HIGH) && (true == pin_status[i]) ) { MIDI.sendNoteOff(note[i] + ptch, 0, ch[i]); pin_status[i] = false; FlexiTimer2::stop(); } } } } void changeModeSetup() { mode = E_MODE_SETUP; setLed(LOW); } void changeModePlay() { mode = E_MODE_PLAY; setLed(HIGH); } void blinkLed() { setLed(0x01 & led_val++); } void setLed(boolean val) { digitalWrite(led_pin, val); }