Midi Wood Keyboard
Mappage sur Ableton :)
Components and supplies
12
Tactile Switch, Top Actuated
1
Arduino UNO
2
Rotary Potentiometer, 10 kohm
Project description
Code
Encore un teste midi clavier
csharp
//THANK "PretEnGineering" for the structure of code.
1// MAIS CELUI CI CEST LE BON :) 2//CODE N°24, CINQUIEME SEMAINE DE PROG 3//THANK "PretEnGineering" POUR LA STRUCTURE ;) 4//Beru 5#include <MIDI.h> 6//#include <pitches.h> 7MIDI_CREATE_DEFAULT_INSTANCE(); // DECLARATION PIN DIGITAL 8int buttonZpin = 2; 9int buttonApin = 3; 10int buttonBpin = 4; 11int buttonCpin = 5; 12int buttonDpin = 6; 13int buttonEpin = 7; 14int buttonFpin = 8; 15int buttonGpin = 9; 16int buttonHpin = 10; 17int buttonIpin = 11; 18int buttonJpin = 12; 19int buttonKpin = 13; 20 //DECLARATION PIN ANALOGIQUE 21int analogpot1 = A0; // POTARD 1 22int analogpot2 = A1; 23 //ROLE DES PIN ANALOGUE 24int analogpot1Old = 0; 25int analogpot2Old = 0; 26int analogpot1New = 0; 27int analogpot2New = 0; 28 // VALEUR DES PIN ANALOGUE = RECONNU POUR LE MAPPAGE ABLETON COMME " C-54 " & " C-55 " ETC... 29#define analogpot1CC 54 30#define analogpot2CC 55 31 32void setup() { 33 34MIDI.begin (); // ETAT DES PIN DIGITAL 35 36pinMode(buttonZpin, INPUT_PULLUP);// UTILISE LA RESISTANCE DE LA CARTE // A ENLEVER SI RESISTANCE // ATTENTION AU CHANGEMENT DE BRANCHEMENT DES BOUTTON !!! 37pinMode(buttonApin, INPUT_PULLUP); 38pinMode(buttonBpin, INPUT_PULLUP); 39pinMode(buttonCpin, INPUT_PULLUP); 40pinMode(buttonDpin, INPUT_PULLUP); 41pinMode(buttonEpin, INPUT_PULLUP); 42pinMode(buttonFpin, INPUT_PULLUP); 43pinMode(buttonGpin, INPUT_PULLUP); 44pinMode(buttonHpin, INPUT_PULLUP); 45pinMode(buttonIpin, INPUT_PULLUP); 46pinMode(buttonJpin, INPUT_PULLUP); 47pinMode(buttonKpin, INPUT_PULLUP); 48 49pinMode(analogpot1, INPUT); 50pinMode(analogpot2, INPUT); 51 52Serial.begin(9600); ///////////////////////////////////////////////////////// BAULT Serial.begin(115200); 53} 54 55void loop() { 56 // ETAT ACTUEL DES PIN ANALOGUE 57static bool buttonZvalueOld = HIGH; 58static bool buttonAvalueOld = HIGH; 59static bool buttonBvalueOld = HIGH; 60static bool buttonCvalueOld = HIGH; 61static bool buttonDvalueOld = HIGH; 62static bool buttonEvalueOld = HIGH; 63static bool buttonFvalueOld = HIGH; 64static bool buttonGvalueOld = HIGH; 65static bool buttonHvalueOld = HIGH; 66static bool buttonIvalueOld = HIGH; 67static bool buttonJvalueOld = HIGH; 68static bool buttonKvalueOld = HIGH; 69 70bool buttonZvalueNew = digitalRead(buttonZpin); 71bool buttonAvalueNew = digitalRead(buttonApin); 72bool buttonBvalueNew = digitalRead(buttonBpin); 73bool buttonCvalueNew = digitalRead(buttonCpin); 74bool buttonDvalueNew = digitalRead(buttonDpin); 75bool buttonEvalueNew = digitalRead(buttonEpin); 76bool buttonFvalueNew = digitalRead(buttonFpin); 77bool buttonGvalueNew = digitalRead(buttonGpin); 78bool buttonHvalueNew = digitalRead(buttonHpin); 79bool buttonIvalueNew = digitalRead(buttonIpin); 80bool buttonJvalueNew = digitalRead(buttonJpin); 81bool buttonKvalueNew = digitalRead(buttonKpin); 82 83////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 84//NOTE SANS LES DIESES | RANGEE PAR 2 OCTAVES, SOIT LA CAPACIT2 DU CLAVIER MIDI BOIS // 85// OCTAVE + 28 30 32 33 35 37 39 40 42 44 45 47 48 49 51 FREQUENCES BASSES = NOTES GRAVES // 86// OCTAVES EN PROG 52,54,56,57,59,61,63,64,66,68,69,71,73,75 // 87// OCTAVE - 64 66 68 69 71 73 75 76 78 80 81 83 85 87 88 FREQUENCES HAUTES = NOTES AIGUES // 88////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 89 90 91 if (buttonAvalueNew != buttonAvalueOld){ /////////////////////////////////////////PREMIERE NOTE///////////////////////////////////////////////////////////// 92 if (buttonAvalueNew == LOW){ // SI J APPUIE ...|`||METTRE A L ETAT "HIGH" SI RESISTANCES, ET BRANCHEZ AU GROUND LE BOUTON;) ET ENLEVER INPUT_PULLUP DANS LA DECLARATION 93 MIDI.sendNoteOn(52, 127, 1); // (NUM NOTE,VELOCITE,ETAT?) 94 Serial.println("Note A On"); 95 } 96 else { 97 MIDI.sendNoteOff(52, 0, 1); 98 Serial.println("Note A Off"); 99 } 100 buttonAvalueOld = buttonAvalueNew; 101 }//////////////////////////////////////////////////////////////////////////// B /////////////////////////////////////////////////////////////////////////////// 102 103 if (buttonBvalueNew != buttonBvalueOld){ 104 if (buttonBvalueNew == LOW){ 105 MIDI.sendNoteOn(54, 127, 1); 106 Serial.println("Note B On"); 107 } 108 else { 109 MIDI.sendNoteOff(54, 0, 1); 110 Serial.println("Note B Off"); 111 } 112 buttonBvalueOld = buttonBvalueNew; 113 }//////////////////////////////////////////////////////////////////////////// C ///////////////////////////////////////////////////////////////////////// 114 115 if (buttonCvalueNew != buttonCvalueOld){ 116 if (buttonCvalueNew == LOW){ 117 MIDI.sendNoteOn(56, 127, 1); 118 Serial.println("Note C On"); 119 } 120 else { 121 MIDI.sendNoteOff(56, 0, 1); 122 Serial.println("Note C Off"); 123 } 124 buttonCvalueOld = buttonCvalueNew; 125 }//////////////////////////////////////////////////////////////////////////// D /////////////////////////////////////////////////////////////////////// 126 127 if (buttonDvalueNew != buttonDvalueOld){ 128 if (buttonDvalueNew == LOW){ 129 MIDI.sendNoteOn(57, 127, 1); 130 Serial.println("Note D On"); 131 } 132 else { 133 MIDI.sendNoteOff(57, 0, 1); 134 Serial.println("Note D Off"); 135 } 136 buttonDvalueOld = buttonDvalueNew; 137 }/////////////////////////////////////////////////////////////////////////// E ///////////////////////////////////////////////////////////////////// 138 139 if (buttonEvalueNew != buttonEvalueOld){ 140 if (buttonEvalueNew == LOW){ 141 MIDI.sendNoteOn(59, 127, 1); 142 Serial.println("Note E On"); 143 } 144 else { 145 MIDI.sendNoteOff(59, 0, 1); 146 Serial.println("Note E Off"); 147 } 148 buttonEvalueOld = buttonEvalueNew; 149 } 150///////////////////////////////////////////52,54,56,57,59,61,63,64,66,68,69,71,73,75//////// F /////////////////////////////////////////////////////////// 151 if (buttonFvalueNew != buttonFvalueOld){ 152 if (buttonFvalueNew == LOW){ 153 MIDI.sendNoteOn(61, 127, 1); 154 Serial.println("Note F On"); 155 } 156 else { 157 MIDI.sendNoteOff(61, 0, 1); 158 Serial.println("Note F Off"); 159 } 160 buttonFvalueOld = buttonFvalueNew; 161 }//////////////////////////////////////////////////////////////////////// G /////////////////////////////////////////////////////////////////////////// 162 163 if (buttonGvalueNew != buttonGvalueOld){ 164 if (buttonGvalueNew == LOW){ 165 MIDI.sendNoteOn(63, 127, 1); 166 Serial.println("Note G On"); 167 } 168 else { 169 MIDI.sendNoteOff(63, 0, 1); 170 Serial.println("Note G Off"); 171 } 172 buttonGvalueOld = buttonGvalueNew; 173 }////////////////////////////////////////////////////////////////////////////// H ////////////////////////////////////////////////////////////////////// 174 175 if (buttonHvalueNew != buttonHvalueOld){ 176 if (buttonHvalueNew == LOW){ 177 MIDI.sendNoteOn(64, 127, 1); 178 Serial.println("Note H On"); 179 } 180 else { 181 MIDI.sendNoteOff(64, 0, 1); 182 Serial.println("Note H Off"); 183 } 184 buttonHvalueOld = buttonHvalueNew; 185 }//////////////////////////////////////////////////////////////////////// I ////////////////////////////////////////////////////////////////////////////// 186 187 if (buttonIvalueNew != buttonIvalueOld){ 188 if (buttonIvalueNew == LOW){ 189 MIDI.sendNoteOn(66, 127, 1); 190 Serial.println("Note I On"); 191 } 192 else { 193 MIDI.sendNoteOff(66, 0, 1); 194 Serial.println("Note I Off"); 195 } 196 buttonIvalueOld = buttonIvalueNew; 197 }///////////////////////////////////////////////////////////////////// J ///////////////////////////////////////////////////////////////////////////////// 198 199 if (buttonJvalueNew != buttonJvalueOld){ 200 if (buttonJvalueNew == LOW){ 201 MIDI.sendNoteOn(68, 127, 1); 202 Serial.println("Note J On"); 203 } 204 else { 205 MIDI.sendNoteOff(68, 0, 1); 206 Serial.println("Note J Off"); 207 } 208 buttonJvalueOld = buttonJvalueNew; 209 } 210//////////////////////////////////////////52,54,56,57,59,61,63,64,66,68,69,71,73,75//// K ////////////////////////////////////////////////////////////////////// 211 if (buttonKvalueNew != buttonKvalueOld){ 212 if (buttonKvalueNew == LOW){ 213 MIDI.sendNoteOn(69, 127, 1); 214 Serial.println("Note K On"); 215 } 216 217 else { 218 MIDI.sendNoteOff(69, 0, 1); 219 Serial.println("Note K Off"); 220 } 221 buttonKvalueOld = buttonKvalueNew; 222 }/////////////////////////////////////////////////////////////////////// Z //////////////////////////////////////////////////////////////////////////////////// 223 224 if (buttonZvalueNew != buttonZvalueOld){ 225 if (buttonZvalueNew == LOW){ 226 MIDI.sendNoteOn(50, 127, 1); 227 Serial.println("Note Z On"); 228 } 229 else { 230 MIDI.sendNoteOff(50, 0, 1); 231 Serial.println("Note Z Off"); 232 } 233 234 buttonZvalueOld = buttonZvalueNew; 235 }/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 236 237 238/////////////////////////////////////////////////////-POTARDS-///////////////////////////////////////////////////////////////////////////////////////////// 239 240int pot1 = analogRead(A0); 241int pot2 = analogRead(A1); 242int analogpot1New = analogRead(A0); 243int analogpot2New = analogRead(A1); 244 245 if (analogpot1New - analogpot1Old >= 35 || analogpot1Old - analogpot1New >= 35) {//////////////////////// POTARD 1 //////////////////////////////////////// 246 analogpot1Old = analogpot1New; 247 analogpot1New = (map(analogpot1New, 1023, 0, 0, 120)); 248 analogpot1New = (constrain(analogpot1New, 0, 120)); 249 MIDI.sendControlChange(analogpot1CC, analogpot1New, 1); 250// Serial.print ("pot: "); 251// Serial.println(pot1); 252// Serial.print("potread: "); 253// Serial.println(analogpot1New); 254 } 255 256 if (analogpot2New - analogpot2Old >= 35 || analogpot2Old - analogpot2New >= 35) {////////////////////// POTARD 2 ///////////////////////////////////////// 257 analogpot2Old = analogpot2New; 258 analogpot2New = (map(analogpot2New, 1023, 0, 0, 120)); 259 analogpot2New = (constrain(analogpot2New, 0, 120)); 260 MIDI.sendControlChange(analogpot2CC, analogpot2New, 1); 261// Serial.print ("pot: "); 262// Serial.println(pot2); 263// Serial.print("potread: "); 264// Serial.println(analogpot2New); 265 } 266 267delay(25); 268}
Downloadable files
untitled
untitled

untitled
untitled

Comments
Only logged in users can leave comments