Last active
December 22, 2015 02:38
-
-
Save vasmani/6404682 to your computer and use it in GitHub Desktop.
MIDI!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <MIDI.h> | |
| #include <CapacitiveSensor.h> | |
| int threshold = 2000, // for 10Mohm | |
| threshold2 = 200, // for 1Mohm | |
| channel = 1, velocity = 100, instrument = 0; | |
| boolean status1 = false, prev_status1 = false, | |
| status2 = false, prev_status2 = false, | |
| status3 = false, prev_status3 = false, | |
| status4 = false, prev_status4 = false, | |
| status5 = false, prev_status5 = false, | |
| status6 = false, prev_status6 = false, | |
| status7 = false, prev_status7 = false, | |
| status8 = false, prev_status8 = false, | |
| status9 = false, prev_status9 = false, | |
| status10 = false, prev_status10 = false, | |
| status_a = false, prev_status_a = false; | |
| CapacitiveSensor cs_0_1 = CapacitiveSensor(2,3), cs_0_2 = CapacitiveSensor(2,4), | |
| cs_0_3 = CapacitiveSensor(2,5), cs_0_4 = CapacitiveSensor(2,6), | |
| cs_0_5 = CapacitiveSensor(2,7), cs_0_6 = CapacitiveSensor(2,8), | |
| cs_0_7 = CapacitiveSensor(2,9), cs_0_8 = CapacitiveSensor(2,10), | |
| cs_0_9 = CapacitiveSensor(2,11), cs_0_10 = CapacitiveSensor(2,12); | |
| void sendMidiEvent(int note, boolean on) | |
| { | |
| // Serial.print(note); | |
| if(on){ | |
| MIDI.sendNoteOn(note, velocity, channel); | |
| // Serial.print("on"); | |
| } else { | |
| // Serial.print("off"); | |
| MIDI.sendNoteOff(note, velocity, channel); | |
| } | |
| } | |
| void setup() | |
| { | |
| cs_0_1.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example | |
| Serial.begin(38400); | |
| pinMode(13, OUTPUT); | |
| pinMode(A0, INPUT_PULLUP); | |
| digitalWrite(13, LOW); | |
| } | |
| void loop() | |
| { | |
| long v1 = cs_0_1.capacitiveSensor(30), v2 = cs_0_2.capacitiveSensor(30), | |
| v3 = cs_0_3.capacitiveSensor(30), v4 = cs_0_4.capacitiveSensor(30), | |
| v5 = cs_0_5.capacitiveSensor(30), v6 = cs_0_6.capacitiveSensor(30), | |
| v7 = cs_0_7.capacitiveSensor(30), v8 = cs_0_8.capacitiveSensor(30), | |
| v9 = cs_0_9.capacitiveSensor(30), v10 = cs_0_10.capacitiveSensor(30), | |
| v_a = analogRead(0); // instrument value ++ | |
| int light = LOW; | |
| // note chart : http://www.phys.unsw.edu.au/jw/notes.html | |
| // (C3)48, 50, 52, 53, 55, 57, 59, 60 | |
| status1 = (v1 > threshold); | |
| if(status1 != prev_status1){ | |
| sendMidiEvent(60, status1); | |
| } | |
| status2 = (v2 > threshold); | |
| if(status2 != prev_status2){ | |
| sendMidiEvent(62, status2); | |
| } | |
| status3 = (v3 > threshold); | |
| if(status3 != prev_status3){ | |
| sendMidiEvent(64, status3); | |
| } | |
| status4 = (v4 > threshold); | |
| if(status4 != prev_status4){ | |
| sendMidiEvent(65, status4); | |
| } | |
| status5 = (v5 > threshold); | |
| if(status5 != prev_status5){ | |
| sendMidiEvent(67, status5); | |
| } | |
| status6 = (v6 > threshold); | |
| if(status6 != prev_status6){ | |
| sendMidiEvent(69, status6); | |
| } | |
| status7 = (v7 > threshold); | |
| if(status7 != prev_status7){ | |
| sendMidiEvent(71, status7); | |
| } | |
| status8 = (v8 > threshold2); | |
| if(status8 != prev_status8){ | |
| sendMidiEvent(72, status8); | |
| } | |
| status9 = (v9 > threshold2); | |
| if(status9 != prev_status9){ | |
| sendMidiEvent(74, status9); | |
| } | |
| status10 = (v10 > threshold2); | |
| if(status10 != prev_status10){ | |
| sendMidiEvent(76, status10); | |
| } | |
| status_a = (v_a > 800); | |
| if(status_a != prev_status_a && v_a < 800){ | |
| instrument++; | |
| // Serial.println("instrument++!"); | |
| MIDI.sendProgramChange(instrument, channel); | |
| } | |
| light = (status1+status2+status3+status4+status5+status6+status7+status8+status9+status10 > 0) ? HIGH : LOW; | |
| /* | |
| Serial.print(v1); | |
| Serial.print("\t"); | |
| Serial.print(v2); | |
| Serial.print("\t"); | |
| Serial.print(v3); | |
| Serial.print("\t"); | |
| Serial.print(v4); | |
| Serial.print("\t"); | |
| Serial.print(v5); | |
| Serial.print("\t"); | |
| Serial.print(v6); | |
| Serial.print("\t"); | |
| Serial.print(v7); | |
| Serial.print("\t"); | |
| Serial.print(v8); | |
| Serial.print("\t"); | |
| Serial.print(v9); | |
| Serial.print("\t"); | |
| Serial.println(v10); | |
| */ | |
| digitalWrite(13, light); | |
| delay(20); // arbitrary delay to limit data to serial port | |
| prev_status1 = status1; | |
| prev_status2 = status2; | |
| prev_status3 = status3; | |
| prev_status4 = status4; | |
| prev_status5 = status5; | |
| prev_status6 = status6; | |
| prev_status7 = status7; | |
| prev_status8 = status8; | |
| prev_status9 = status9; | |
| prev_status10 = status10; | |
| prev_status_a = status_a; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment