GM drum pad demo program
使用機材
購入はこちら。
https://www.switch-science.com/catalog/1489/
https://www.switch-science.com/catalog/1966/
https://www.switch-science.com/catalog/1624/
接続(Capacitive Touch Keypadの場合)
LPCXpresso824-MAX | Capacitive Touch Keypad |
---|---|
GND | GND |
A4 | SDA |
A5 | SCL |
D2 | IRQ |
+3V3 | VCC |
接続(Touch Shieldの場合)
Touch Shieldに足の長いピンソケットを半田付けして、動画の様にそのままeVY1ボードに接続します。
制御について
MPR121から取得したタッチ情報を使用して、MIDIのノートオン、ノートオフをeVY1にシリアルで送信しています。ソースコード中の key_tbl[] の値を変更すれば、キーに割り当てた音色を変えることが出来ます。ドラム用音色はこちらを参考にして下さい。
Diff: main.cpp
- Revision:
- 0:771fd7f08681
- Child:
- 1:db4dbd6734e6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 10 05:12:57 2016 +0000 @@ -0,0 +1,95 @@ +/* Drum pad demo program + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * * + * @author Toyomasa Watarai + * @version 1.0 + * @date 10-March-2016 + * + * Sparkfun Touch Sheild + * eVY1 board + * LPCXpresso842-MAX + * + */ + +#include "mbed.h" +#include "MPR121.h" + +DigitalOut myled(LED1); +I2C i2c(A4, A5); +InterruptIn irq(D2); + +#define LED_ON 0 +#define LED_OFF 1 + +MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS); +RawSerial midi(D1, NC); + +const int key_tbl[9] = { + 38, // 9 + 39, // 6 + 41, // 3 + 42, // 8 + 45, // 5 + 49, // 2 + 67, // 7 + 79, // 4 + 36, // 1 +}; + +int key_pressed[9]; + +int main() +{ + touch_pad.init(); + touch_pad.enable(); + + midi.baud(31250); + wait(3.5); // Wait few seconds for booting eVY1-Shleld. + + // Initialize (Phonetic symbols - eVocaloid) + const uint8_t aMsgInit[] = "\xF0\x43\x79\x09\x00\x50\x10" "4 a\0" "\xF7"; + for (uint32_t i = 0; i < sizeof(aMsgInit)-1; midi.putc(aMsgInit[i++])); + + const uint8_t aMsgVol[] = "\xB9\x07\x70"; + for (uint32_t i = 0; i < sizeof(aMsgVol)-1; midi.putc(aMsgVol[i++])); + + while(1) { + if(touch_pad.isPressed()) { + uint16_t button_val = touch_pad.buttonPressed(); + if (button_val != 0) { + for(int i=0; i<9; i++) { + if ((button_val & (1 << i))) { + if (key_pressed[i] == 0) { + midi.putc(0x99); // note on CH10 + midi.putc(key_tbl[i]); // note number + midi.putc(100); // velocity + key_pressed[i] = 1; + } + } + } + } else { + for(int i=0; i<9; i++) { + if ((button_val & (1 << i)) == 0) { + key_pressed[i] = 0; + midi.putc(0x89); // note off CH10 + midi.putc(key_tbl[i]); // note number + midi.putc(0); // velocity + } + } + } + myled = (button_val>0) ? LED_ON : LED_OFF; + } + } +}