Mono-Tabla MIDI Controller
Objective:
Prototype a MIDI controller
Audience:
Musicians experienced with playing the Tabla.
Components:
Arduino, MIDI tone generator, switches, wires, mount board.
Code:
#include <SoftwareSerial.h> int keys[] = {8, 9, 10, 11}; int lastKeyState[] = {0, 0, 0, 0}; int keyCount = 4; int baseNote = 40; int lastSwitchState = 0; int currentSwitchState = 0; int vol = 0; SoftwareSerial midiSerial(2, 3); void setup() { Serial.begin(9600); midiSerial.begin(31250); for (int k = 0; k < keyCount; k++) { pinMode(keys[k], INPUT); } } void loop() { int currentKeyState[] = {0, 0, 0, 0}; for (int k = 0; k < keyCount; k++) { currentKeyState[k] = digitalRead(keys[k]); if (currentKeyState[k] != lastKeyState[k]) { int thisNote = k + baseNote; int thisCommand = 0; if (currentKeyState[k] == HIGH ) { thisCommand = 0x90; Serial.print(" on: "); } else { thisCommand = 0x80; Serial.print("off: "); } midiCommand(thisCommand, thisNote, 127); Serial.println(thisNote, HEX); lastKeyState[k] = currentKeyState[k]; } } int pitchBendSensor = analogRead(A0); if (pitchBendSensor > 10 ) { byte msb = highByte(pitchBendSensor << 1); byte lsb = lowByte(pitchBendSensor); bitWrite(lsb, 7, 0); midiCommand(0xE0, lsb, msb); } int bassSensor = analogRead (A1); Serial.println(bassSensor); vol = bassSensor/8; currentSwitchState = bassSensor; if (currentSwitchState > 1) { if (lastSwitchState < 1) { midiCommand(0x90, 35, vol); } } else { if (lastSwitchState > 1) { midiCommand(0x90, 35, vol); } } lastSwitchState = currentSwitchState; delay(50); } void midiCommand(byte cmd, byte data1, byte data2) { midiSerial.write(cmd); midiSerial.write(data1); midiSerial.write(data2); }