111 lines
2.7 KiB
C++
111 lines
2.7 KiB
C++
#define SEL_A_IN D2
|
|
#define SEL_A_LED D3
|
|
#define SEL_B_IN D4
|
|
#define SEL_B_LED D5
|
|
#define SEL_C_IN D6
|
|
#define SEL_C_LED D7
|
|
#define SEL_D_IN D8
|
|
#define SEL_D_LED D9
|
|
|
|
#define SUST_IN D10
|
|
#define EXPR_IN A0
|
|
|
|
void setup() {
|
|
pinMode( SEL_A_IN, INPUT_PULLUP );
|
|
pinMode( SEL_A_LED, OUTPUT );
|
|
pinMode( SEL_B_IN, INPUT_PULLUP );
|
|
pinMode( SEL_B_LED, OUTPUT );
|
|
pinMode( SEL_C_IN, INPUT_PULLUP );
|
|
pinMode( SEL_C_LED, OUTPUT );
|
|
pinMode( SEL_D_IN, INPUT_PULLUP );
|
|
pinMode( SEL_D_LED, OUTPUT );
|
|
|
|
pinMode( SUST_IN, INPUT_PULLUP );
|
|
pinMode( EXPR_IN, INPUT_PULLUP );
|
|
|
|
Serial.begin(31250);
|
|
}
|
|
|
|
int last_expr_val = 0;
|
|
int last_sust_val = 0;
|
|
|
|
#define NOTE_OFF 0x8
|
|
#define NOTE_ON 0x9
|
|
#define AFTERTOUCH 0xA
|
|
#define CONTROL_CHANGE 0xB
|
|
#define PATCH_CHANGE 0xC
|
|
#define CHANNEL_PRESSURE 0xD
|
|
#define PITCH_BEND 0xE
|
|
#define OTHER 0xF
|
|
|
|
//send MIDI message
|
|
void MIDImessage(int cmd_id, int data1, int data2) {
|
|
int channel = 0;
|
|
int cmd_byte = (cmd_id << 4) | (channel & 0xf);
|
|
Serial.write(cmd_byte);//send command byte
|
|
Serial.write(data1);//send data byte #1
|
|
Serial.write(data2);//send data byte #2
|
|
}
|
|
|
|
void loop() {
|
|
delay(100);
|
|
|
|
if( digitalRead( SUST_IN ) == LOW ) {
|
|
if( last_sust_val != 1 ) {
|
|
last_sust_val = 1;
|
|
MIDImessage( CONTROL_CHANGE, 0x42, 0x7f );
|
|
}
|
|
} else {
|
|
if( last_sust_val != 0 ) {
|
|
last_sust_val = 0;
|
|
MIDImessage( CONTROL_CHANGE, 0x42, 0x00 );
|
|
}
|
|
}
|
|
|
|
int expr_val = analogRead( EXPR_IN );
|
|
if( expr_val != last_expr_val )
|
|
{
|
|
last_expr_val = expr_val;
|
|
|
|
float expr_val_f = (float)(expr_val - 66) / 590.0;
|
|
if( expr_val_f < 0.0 ){
|
|
expr_val_f = 0.0;
|
|
}
|
|
if( expr_val_f > 1.0 ){
|
|
expr_val_f = 1.0;
|
|
}
|
|
|
|
int val_b = (int)(expr_val_f * 128.0);
|
|
|
|
MIDImessage( CONTROL_CHANGE, 0x0b, val_b );
|
|
}
|
|
|
|
if( digitalRead( SEL_A_IN ) == LOW ) {
|
|
MIDImessage( PATCH_CHANGE, 0x0, 0x0 );
|
|
digitalWrite( SEL_A_LED, HIGH );
|
|
digitalWrite( SEL_B_LED, LOW );
|
|
digitalWrite( SEL_C_LED, LOW );
|
|
digitalWrite( SEL_D_LED, LOW );
|
|
}
|
|
if( digitalRead( SEL_B_IN ) == LOW ) {
|
|
MIDImessage( PATCH_CHANGE, 0x1, 0x1 );
|
|
digitalWrite( SEL_A_LED, LOW );
|
|
digitalWrite( SEL_B_LED, HIGH );
|
|
digitalWrite( SEL_C_LED, LOW );
|
|
digitalWrite( SEL_D_LED, LOW );
|
|
}
|
|
if( digitalRead( SEL_C_IN ) == LOW ) {
|
|
MIDImessage( PATCH_CHANGE, 0x2, 0x2 );
|
|
digitalWrite( SEL_A_LED, LOW );
|
|
digitalWrite( SEL_B_LED, LOW );
|
|
digitalWrite( SEL_C_LED, HIGH );
|
|
digitalWrite( SEL_D_LED, LOW );
|
|
}
|
|
if( digitalRead( SEL_D_IN ) == LOW ) {
|
|
MIDImessage( PATCH_CHANGE, 0x3, 0x3 );
|
|
digitalWrite( SEL_A_LED, LOW );
|
|
digitalWrite( SEL_B_LED, LOW );
|
|
digitalWrite( SEL_C_LED, LOW );
|
|
digitalWrite( SEL_D_LED, HIGH );
|
|
}
|
|
}
|