- /*EvilMaker Orchid (Opensource) 2015 v1.00-d
- by Virtualwiz
- */
-
- void midiSend (int cmd, int pitch, int velocity) {
- Serial.write(cmd);
- Serial.write(pitch);
- Serial.write(velocity);
- }
- const byte buzzer=50;
-
- //Serial to MIDI or Native MIDI?
- boolean debug_mode=true;
-
- const unsigned char kick=36;
- const unsigned char snare=38;
- const unsigned char tom_high=50;
- const unsigned char tom_low=45;
- const unsigned char tom_bass=41;
- const unsigned char crash_left=49;
- const unsigned char crash_right=57;
- const unsigned char hat_open=51; //46
- const unsigned char hat_close=42;
-
- char adc_channel[7] ={
-
- 'A0','A1','A2','A3','A4','A5','A6'
- };
-
- void setup() {
- pinMode(buzzer,OUTPUT);
- pinMode(7,OUTPUT);
- pinMode(6,INPUT);
- pinMode(3,INPUT);
- digitalWrite(3,HIGH);
- digitalWrite(6,HIGH);
- //3 is for Kick and 6 is for hi-hat
-
- //Startup tone
- tone(buzzer,1397,130);
- delay(130);
- tone(buzzer,1568,130);
- delay(130);
- tone(buzzer,1760,150);
- delay(1500);
-
- pinMode(7,OUTPUT);
- if(debug_mode)
- {
- Serial.begin(115200); //Debug mode baud rate
- tone(buzzer,1397,120);
- delay(300);
- tone(buzzer,1397,120);
- delay(1000);
- }
- else
- {
- Serial.begin(31250); //MIDI baud rate
- tone(buzzer,1397,120);
- delay(1000);
- }
- tone(buzzer,1397,300);
- delay(1000);
- }
-
-
- unsigned char adc_sample[7];
- boolean kick_trig_flag=false; //Is Kick already triggered?
-
- //IMPORTANT!
- //Adjust this if your pads are dull or too sensitive
- //{crash, hat, snare, tom_bass, crash_right, tom_high, tom_low}
- unsigned char adc_cutoff[7]= //minimum strength
- {
- 3, 3, 10, 7, 3, 3, 3};
- unsigned char adc_limit[7]= //maximum strength
- {
- 40, 10, 30, 50, 40, 10, 10};
-
-
- void loop() {
-
- digitalWrite(7,HIGH);
- for(byte count=0;count<=6;count++)
- {
- adc_sample[count]=map(analogRead(adc_channel[count]),0,1023,0,254);
- }
-
- //Here is a strange problem
- //0 and 6 can't get their correct value if following code was not written
- adc_sample[6]=map(analogRead(A6),0,1023,0,254);
- adc_sample[0]=map(analogRead(A0),0,1023,0,254);
- //Pls contant me if you know why,thx
-
- digitalWrite(7,LOW);
-
- if(adc_sample[0]>=adc_cutoff[0])
- {
- if(adc_sample[0]>=adc_limit[0])
- adc_sample[0]=adc_limit[0];
- midiSend(0x99,crash_left,map(adc_sample[0],adc_cutoff[0],adc_limit[0],0x00,0x7f));
- // Serial.print("\t");
- //Serial.println(adc_sample[0]);
- }
- if(adc_sample[1]>=adc_cutoff[1])
- {
- if(adc_sample[1]>=adc_limit[1])
- adc_sample[1]=adc_limit[1];
- if(digitalRead(6)==HIGH)
- midiSend(0x99,hat_open,map(adc_sample[1],adc_cutoff[1],adc_limit[1],0x00,0x7f));
- else
- midiSend(0x99,hat_close,map(adc_sample[1],adc_cutoff[1],adc_limit[1],0x00,0x7f));
- }
- if(adc_sample[2]>=adc_cutoff[2])
- {
- if(adc_sample[2]>=adc_limit[2])
- adc_sample[2]=adc_limit[2];
- midiSend(0x99,snare,map(adc_sample[2],adc_cutoff[2],adc_limit[2],0x00,0x7f));
- delay(13); //sorry that my snare pad is too bouncy
- }
- if(adc_sample[3]>=adc_cutoff[3])
- {
- if(adc_sample[3]>=adc_limit[3])
- adc_sample[3]=adc_limit[3];
- midiSend(0x99,tom_bass,map(adc_sample[3],adc_cutoff[3],adc_limit[3],0x00,0x7f));
- }
- if(adc_sample[4]>=adc_cutoff[4])
- {
- if(adc_sample[4]>=adc_limit[4])
- adc_sample[4]=adc_limit[4];
- midiSend(0x99,crash_right,map(adc_sample[4],adc_cutoff[4],adc_limit[4],0x00,0x7f));
- }
- if(adc_sample[5]>=adc_cutoff[5])
- {
- if(adc_sample[5]>=adc_limit[5])
- adc_sample[5]=adc_limit[5];
- midiSend(0x99,tom_high,map(adc_sample[5],adc_cutoff[5],adc_limit[5],0x00,0x7f));
- }
- if(adc_sample[6]>=adc_cutoff[6])
- {
- if(adc_sample[6]>=adc_limit[6])
- adc_sample[6]=adc_limit[6];
- midiSend(0x99,tom_low,map(adc_sample[6],adc_cutoff[6],adc_limit[6],0x00,0x7f));
- }
- if(digitalRead(3)==HIGH)
- {
- kick_trig_flag=false;
- }
- if(digitalRead(3)==LOW)
- {
- if(kick_trig_flag==false)
- {
- midiSend(0x99,kick,0x7f);
- kick_trig_flag=true;
- }
- }
-
- delay(5); //This is the total sensitivity for all the pads
- }
- /*ADC Test
- int val;
- for(int i = 0; i < 8; i++) {
- val = analogRead(i);
- Serial.print("CH");
- Serial.print(i);
- Serial.print("\t Value=");
- Serial.print(val);
- Serial.print("\n");
- delay(20);
- }
- Serial.print("\n");
- delay(1000);
- */
-
- /*MIDI Send Test
- //This is a simple loop for you to check your MIDI bridge and synthesizer.
-
- midiSend(0x99,hat_close, 0x45);
- midiSend(0x99,kick, 0x45);
- delay(300);
- midiSend(0x99,hat_close, 0x45);
- delay(300);
- midiSend(0x99,hat_close, 0x45);
- midiSend(0x99,snare, 0x45);
- delay(300);
- midiSend(0x99,hat_close, 0x45);
- midiSend(0x99,kick, 0x45);
- delay(300);
- midiSend(0x99,hat_close, 0x45);
- midiSend(0x99,kick, 0x45);
- delay(300);
- midiSend(0x99,hat_close, 0x45);
- delay(300);
- midiSend(0x99,hat_close, 0x45);
- midiSend(0x99,snare, 0x45);
- delay(300);
- midiSend(0x99,hat_close, 0x45);
- delay(300);
-
- */
复制代码
可以选择串口转MIDI(9600bps)或真MIDI(31250bps)两种波特率,看你怎么方便连接了~
各个板子的灵敏度在程序中也可以调节。
|