Components and supplies
Aluminium Foil
Through Hole Resistor, 500 kohm
Balsa wood Block
Arduino Mega 2560
Apps and platforms
FL studio
LoopMIDI
Arduino IDE
HairlessMIDI
Project description
Code
Code for Data Capture/Process and MIDI massage Generation
arduino
1// Arduino Based Continuous MIDI controller 2// Code by: Abhilash Patel 3// Contact: abhilashpatel121@gmail.com 4// More details on the project available at: 5 6 7#include <CapacitiveSensor.h> 8float raw[50],pressure[33]; 9byte resolution=17; 10float key[33]; 11float play_acc,play_key,play_pressure; 12int play_stat[33], play_change; 13int exp_val; 14float exp_data[10]={22.63,16,11.31,8,5.66,4,2.83,2,1.41,1}; // Exponential smooothing 15float exp_total; 16long a,b,c; 17int play_bend,play_note,play_at; 18 19 int noteON = 144;//144 = 10010000 in binary, note on command 20 int velocity = 120;//velocity of MIDI notes, must be between 0 and 127 21 22 23// Edit this section as per your connection layout 24CapacitiveSensor p1 = CapacitiveSensor(13,12); 25CapacitiveSensor p2 = CapacitiveSensor(13,11); 26CapacitiveSensor p3 = CapacitiveSensor(13,10); 27CapacitiveSensor p4 = CapacitiveSensor(13,9); 28CapacitiveSensor p5 = CapacitiveSensor(13,8); 29 30CapacitiveSensor p6 = CapacitiveSensor(13,7); 31CapacitiveSensor p7 = CapacitiveSensor(13,6); 32CapacitiveSensor p8 = CapacitiveSensor(13,A1); 33CapacitiveSensor p9 = CapacitiveSensor(13,A2); 34CapacitiveSensor p10 = CapacitiveSensor(13,A3); 35 36 37CapacitiveSensor p11 = CapacitiveSensor(13,A4); 38CapacitiveSensor p12 = CapacitiveSensor(13,A5); 39CapacitiveSensor p13 = CapacitiveSensor(13,A6); 40CapacitiveSensor p14 = CapacitiveSensor(13,A7); 41CapacitiveSensor p15 = CapacitiveSensor(13,A8); 42 43CapacitiveSensor p16 = CapacitiveSensor(13,A9); 44CapacitiveSensor p17 = CapacitiveSensor(13,A10); 45CapacitiveSensor p18 = CapacitiveSensor(13,A11); 46CapacitiveSensor p19 = CapacitiveSensor(13,A12); 47CapacitiveSensor p20 = CapacitiveSensor(13,A13); 48 49 50CapacitiveSensor p21 = CapacitiveSensor(13,A14); 51CapacitiveSensor p22 = CapacitiveSensor(13,42); 52CapacitiveSensor p23 = CapacitiveSensor(13,44); 53CapacitiveSensor p24 = CapacitiveSensor(13,51); 54CapacitiveSensor p25 = CapacitiveSensor(13,49); 55 56CapacitiveSensor p26 = CapacitiveSensor(13,47); 57CapacitiveSensor p27 = CapacitiveSensor(13,45); 58CapacitiveSensor p28 = CapacitiveSensor(13,43); 59CapacitiveSensor p29 = CapacitiveSensor(13,41); 60CapacitiveSensor p30 = CapacitiveSensor(13,39); 61 62 63CapacitiveSensor p31 = CapacitiveSensor(13,37); 64CapacitiveSensor p32 = CapacitiveSensor(13,35); 65CapacitiveSensor p33 = CapacitiveSensor(13,24); 66CapacitiveSensor p34 = CapacitiveSensor(13,31); 67CapacitiveSensor p35 = CapacitiveSensor(13,29); 68 69CapacitiveSensor p36 = CapacitiveSensor(13,27); 70CapacitiveSensor p37 = CapacitiveSensor(13,25); 71CapacitiveSensor p38 = CapacitiveSensor(13,23); 72CapacitiveSensor p39 = CapacitiveSensor(13,38); 73CapacitiveSensor p40 = CapacitiveSensor(13,40); 74 75 76CapacitiveSensor p41 = CapacitiveSensor(13,22); 77CapacitiveSensor p42 = CapacitiveSensor(13,2); 78CapacitiveSensor p43 = CapacitiveSensor(13,26); 79CapacitiveSensor p44 = CapacitiveSensor(13,28); 80CapacitiveSensor p45 = CapacitiveSensor(13,30); 81 82CapacitiveSensor p46 = CapacitiveSensor(13,32); 83CapacitiveSensor p47 = CapacitiveSensor(13,34); 84CapacitiveSensor p48 = CapacitiveSensor(13,36); 85 86 87 88void setup() { 89Serial.begin(115200); 90exp_val=sizeof(exp_data)/sizeof(exp_data[0]); 91for(int i=0;i<10;i++){exp_total=exp_total+exp_data[i];} 92raw_cap(); 93delay(100); 94} 95 96 97void loop() { 98 99raw_cap(); 100data_process(); 101 102} 103 104 105void raw_cap() 106{ 107 raw[1]=p1.capacitiveSensor(resolution); 108 raw[2]=p2.capacitiveSensor(resolution); 109 raw[3]=p3.capacitiveSensor(resolution); 110 raw[4]=p4.capacitiveSensor(resolution); 111 raw[5]=p5.capacitiveSensor(resolution); 112 113 raw[6]=p6.capacitiveSensor(resolution); 114 raw[7]=p7.capacitiveSensor(resolution); 115 raw[8]=p8.capacitiveSensor(resolution); 116 raw[9]=p9.capacitiveSensor(resolution); 117 raw[10]=p10.capacitiveSensor(resolution); 118 119 120 raw[11]=p11.capacitiveSensor(resolution); 121 raw[12]=p12.capacitiveSensor(resolution); 122 raw[13]=p13.capacitiveSensor(resolution); 123 raw[14]=p14.capacitiveSensor(resolution); 124 raw[15]=p15.capacitiveSensor(resolution); 125 126 raw[16]=p16.capacitiveSensor(resolution); 127 raw[17]=p17.capacitiveSensor(resolution); 128 raw[18]=p18.capacitiveSensor(resolution); 129 raw[19]=p19.capacitiveSensor(resolution); 130 raw[20]=p20.capacitiveSensor(resolution); 131 132 133 raw[21]=p21.capacitiveSensor(resolution); 134 raw[22]=p22.capacitiveSensor(resolution); 135 raw[23]=p23.capacitiveSensor(resolution); 136 raw[24]=p24.capacitiveSensor(resolution); 137 raw[25]=p25.capacitiveSensor(resolution); 138 139 raw[26]=p26.capacitiveSensor(resolution); 140 raw[27]=p27.capacitiveSensor(resolution); 141 raw[28]=p28.capacitiveSensor(resolution); 142 raw[29]=p29.capacitiveSensor(resolution); 143 raw[30]=p30.capacitiveSensor(resolution); 144 145 146 raw[31]=p31.capacitiveSensor(resolution); 147 raw[32]=p32.capacitiveSensor(resolution); 148 raw[33]=p33.capacitiveSensor(resolution); 149 raw[34]=p34.capacitiveSensor(resolution); 150 raw[35]=p35.capacitiveSensor(resolution); 151 152 raw[36]=p36.capacitiveSensor(resolution); 153 raw[37]=p37.capacitiveSensor(resolution); 154 raw[38]=p38.capacitiveSensor(resolution); 155 raw[39]=p39.capacitiveSensor(resolution); 156 raw[40]=p40.capacitiveSensor(resolution); 157 158 159 raw[41]=p41.capacitiveSensor(resolution); 160 raw[42]=p42.capacitiveSensor(resolution); 161 raw[43]=p43.capacitiveSensor(resolution); 162 raw[44]=p44.capacitiveSensor(resolution); 163 raw[45]=p45.capacitiveSensor(resolution); 164 165 raw[46]=p46.capacitiveSensor(resolution); 166 raw[47]=p47.capacitiveSensor(resolution); 167 raw[48]=p48.capacitiveSensor(resolution); 168} 169 170 171void data_process() 172{ 173 174float avg,max_val,tt1,tt2; 175int max_ind; 176int bend_base; 177avg=0;max_val=0;max_ind=0;tt1=0;tt2=0; 178 179 180for(int i=1;i<49;i++) {avg=avg+raw[i];} 181avg=avg/48; 182 183for(int i=1;i<49;i++) 184{raw[i]=raw[i]-avg;} 185 186 187for(int i=1;i<49;i++){if(raw[i]>max_val){max_ind=i; max_val=raw[i];}} 188 189for(int i=30; i>0; i--) 190{ 191 key[i]=key[i-1]; 192 pressure[i]=pressure[i-1]; 193 play_stat[i]=play_stat[i-1]; 194} 195 196key[0]=(raw[max_ind-1]*(max_ind-1)+raw[max_ind]*(max_ind)+raw[max_ind+1]*(max_ind+1))/(raw[max_ind-1]+raw[max_ind]+raw[max_ind+1]); 197pressure[0]=raw[max_ind];//(raw[max_ind]+raw[max_ind-1]+raw[max_ind+1])/3; 198//Serial.println(raw[max_ind]); 199//Serial.println(pressure[0]); 200 201 202 203if(raw[max_ind]>=17){play_stat[0]=1;} else{play_stat[0]=0;} // the value 17 decided by trial and error. 204//Serial.println(key[0]); 205 206if(play_stat[0]==1 && play_stat[1]==0) 207 {for(int i=0;i<15;i++) 208 { 209 key[i]=key[0]; 210 } 211 exp_smooth(); 212 play_note=play_acc; 213 if(play_acc-play_note>0.5){play_note=play_note+1;} 214 bend_base=512*(play_acc-play_note); 215 MIDImessage(144, play_note, velocity); 216 //Serial.print("ON");Serial.print("\ 217"); 218 } 219 220 221if(play_stat[0]==0 && play_stat[1]==1) 222 {MIDImessage(144, play_note, 0); 223 //Serial.print("OFF");Serial.print("\ 224"); 225 } 226 227if(play_stat[0]==1) 228 { 229 exp_smooth(); 230 play_bend=8192+512*(play_acc-play_note)-bend_base; 231 if(play_bend>16384){play_bend=16383;} 232 if(play_bend<0){play_bend=0;} 233 play_at=play_pressure; 234 if(play_at>127){play_at=126;} 235 MIDImessage(224,(play_bend&127),(play_bend>>7)); 236 MIDImessage(208, 0, play_at); //253 237 //Serial.print(play_at);Serial.print("\ ");Serial.print(play_acc);Serial.print("\ ");Serial.print(play_note);Serial.print("\ ");Serial.print(play_bend);Serial.print("\ 238"); 239 240 } 241 242//Serial.println(play_at); 243/* 244Serial.print(play_note); 245Serial.print("\ "); 246Serial.print(play_stat[0]); 247Serial.print("\ "); 248Serial.print(play_acc); 249Serial.print("\ "); 250Serial.print(play_bend); 251Serial.print("\ "); 252Serial.print(play_pressure); 253Serial.print("\ "); 254Serial.print(max_val); 255Serial.print("\ "); 256*/ 257} 258 259 260void exp_smooth() 261{ 262 play_acc=0; 263 play_pressure=0; 264 for(int i=0; i<10; i++) 265 { 266 play_acc=play_acc+exp_data[i]*key[i]; 267 play_pressure=play_pressure+exp_data[i]*pressure[i]; 268 } 269 play_acc=54.25+play_acc/(2*exp_total); 270 play_acc=play_acc-1; 271 play_pressure=play_pressure/exp_total; // scalling to match 127 272} 273 274 275void MIDImessage(int command, int data1, int data2) { 276 Serial.write(command);//send command byte 277 Serial.write(data1);//send data byte #1 278 Serial.write(data2);//send data byte #2 279}
continuum_kryboard.ino
arduino
Code for Data Capture/Process and MIDI massage Generation
arduino
1// Arduino Based Continuous MIDI controller 2// Code by: Abhilash Patel 3// 4 Contact: abhilashpatel121@gmail.com 5// More details on the project available 6 at: 7 8 9#include <CapacitiveSensor.h> 10float raw[50],pressure[33]; 11byte 12 resolution=17; 13float key[33]; 14float play_acc,play_key,play_pressure; 15int 16 play_stat[33], play_change; 17int exp_val; 18float exp_data[10]={22.63,16,11.31,8,5.66,4,2.83,2,1.41,1}; 19 // Exponential smooothing 20float exp_total; 21long a,b,c; 22int play_bend,play_note,play_at; 23 24 25 int noteON = 144;//144 = 10010000 in binary, note on command 26 int velocity = 27 120;//velocity of MIDI notes, must be between 0 and 127 28 29 30// Edit this 31 section as per your connection layout 32CapacitiveSensor p1 = CapacitiveSensor(13,12); 33 34CapacitiveSensor p2 = CapacitiveSensor(13,11); 35CapacitiveSensor p3 = 36 CapacitiveSensor(13,10); 37CapacitiveSensor p4 = CapacitiveSensor(13,9); 38CapacitiveSensor 39 p5 = CapacitiveSensor(13,8); 40 41CapacitiveSensor p6 = CapacitiveSensor(13,7); 42 43CapacitiveSensor p7 = CapacitiveSensor(13,6); 44CapacitiveSensor p8 = 45 CapacitiveSensor(13,A1); 46CapacitiveSensor p9 = CapacitiveSensor(13,A2); 47CapacitiveSensor 48 p10 = CapacitiveSensor(13,A3); 49 50 51CapacitiveSensor p11 = CapacitiveSensor(13,A4); 52CapacitiveSensor 53 p12 = CapacitiveSensor(13,A5); 54CapacitiveSensor p13 = CapacitiveSensor(13,A6); 55 56CapacitiveSensor p14 = CapacitiveSensor(13,A7); 57CapacitiveSensor p15 58 = CapacitiveSensor(13,A8); 59 60CapacitiveSensor p16 = CapacitiveSensor(13,A9); 61CapacitiveSensor 62 p17 = CapacitiveSensor(13,A10); 63CapacitiveSensor p18 = CapacitiveSensor(13,A11); 64 65CapacitiveSensor p19 = CapacitiveSensor(13,A12); 66CapacitiveSensor p20 67 = CapacitiveSensor(13,A13); 68 69 70CapacitiveSensor p21 = CapacitiveSensor(13,A14); 71 72CapacitiveSensor p22 = CapacitiveSensor(13,42); 73CapacitiveSensor p23 74 = CapacitiveSensor(13,44); 75CapacitiveSensor p24 = CapacitiveSensor(13,51); 76CapacitiveSensor 77 p25 = CapacitiveSensor(13,49); 78 79CapacitiveSensor p26 = CapacitiveSensor(13,47); 80 81CapacitiveSensor p27 = CapacitiveSensor(13,45); 82CapacitiveSensor p28 83 = CapacitiveSensor(13,43); 84CapacitiveSensor p29 = CapacitiveSensor(13,41); 85 86CapacitiveSensor p30 = CapacitiveSensor(13,39); 87 88 89CapacitiveSensor 90 p31 = CapacitiveSensor(13,37); 91CapacitiveSensor p32 = CapacitiveSensor(13,35); 92 93CapacitiveSensor p33 = CapacitiveSensor(13,24); 94CapacitiveSensor p34 95 = CapacitiveSensor(13,31); 96CapacitiveSensor p35 = CapacitiveSensor(13,29); 97 98CapacitiveSensor 99 p36 = CapacitiveSensor(13,27); 100CapacitiveSensor p37 = CapacitiveSensor(13,25); 101 102CapacitiveSensor p38 = CapacitiveSensor(13,23); 103CapacitiveSensor p39 104 = CapacitiveSensor(13,38); 105CapacitiveSensor p40 = CapacitiveSensor(13,40); 106 107 108CapacitiveSensor 109 p41 = CapacitiveSensor(13,22); 110CapacitiveSensor p42 = CapacitiveSensor(13,2); 111 112CapacitiveSensor p43 = CapacitiveSensor(13,26); 113CapacitiveSensor p44 114 = CapacitiveSensor(13,28); 115CapacitiveSensor p45 = CapacitiveSensor(13,30); 116 117 118CapacitiveSensor p46 = CapacitiveSensor(13,32); 119CapacitiveSensor p47 120 = CapacitiveSensor(13,34); 121CapacitiveSensor p48 = CapacitiveSensor(13,36); 122 123 124 125void 126 setup() { 127Serial.begin(115200); 128exp_val=sizeof(exp_data)/sizeof(exp_data[0]); 129for(int 130 i=0;i<10;i++){exp_total=exp_total+exp_data[i];} 131raw_cap(); 132delay(100); 133} 134 135 136void 137 loop() { 138 139raw_cap(); 140data_process(); 141 142} 143 144 145void raw_cap() 146{ 147 148 raw[1]=p1.capacitiveSensor(resolution); 149 raw[2]=p2.capacitiveSensor(resolution); 150 151 raw[3]=p3.capacitiveSensor(resolution); 152 raw[4]=p4.capacitiveSensor(resolution); 153 154 raw[5]=p5.capacitiveSensor(resolution); 155 156 raw[6]=p6.capacitiveSensor(resolution); 157 158 raw[7]=p7.capacitiveSensor(resolution); 159 raw[8]=p8.capacitiveSensor(resolution); 160 161 raw[9]=p9.capacitiveSensor(resolution); 162 raw[10]=p10.capacitiveSensor(resolution); 163 164 165 166 raw[11]=p11.capacitiveSensor(resolution); 167 raw[12]=p12.capacitiveSensor(resolution); 168 169 raw[13]=p13.capacitiveSensor(resolution); 170 raw[14]=p14.capacitiveSensor(resolution); 171 172 raw[15]=p15.capacitiveSensor(resolution); 173 174 raw[16]=p16.capacitiveSensor(resolution); 175 176 raw[17]=p17.capacitiveSensor(resolution); 177 raw[18]=p18.capacitiveSensor(resolution); 178 179 raw[19]=p19.capacitiveSensor(resolution); 180 raw[20]=p20.capacitiveSensor(resolution); 181 182 183 184 raw[21]=p21.capacitiveSensor(resolution); 185 raw[22]=p22.capacitiveSensor(resolution); 186 187 raw[23]=p23.capacitiveSensor(resolution); 188 raw[24]=p24.capacitiveSensor(resolution); 189 190 raw[25]=p25.capacitiveSensor(resolution); 191 192 raw[26]=p26.capacitiveSensor(resolution); 193 194 raw[27]=p27.capacitiveSensor(resolution); 195 raw[28]=p28.capacitiveSensor(resolution); 196 197 raw[29]=p29.capacitiveSensor(resolution); 198 raw[30]=p30.capacitiveSensor(resolution); 199 200 201 202 raw[31]=p31.capacitiveSensor(resolution); 203 raw[32]=p32.capacitiveSensor(resolution); 204 205 raw[33]=p33.capacitiveSensor(resolution); 206 raw[34]=p34.capacitiveSensor(resolution); 207 208 raw[35]=p35.capacitiveSensor(resolution); 209 210 raw[36]=p36.capacitiveSensor(resolution); 211 212 raw[37]=p37.capacitiveSensor(resolution); 213 raw[38]=p38.capacitiveSensor(resolution); 214 215 raw[39]=p39.capacitiveSensor(resolution); 216 raw[40]=p40.capacitiveSensor(resolution); 217 218 219 220 raw[41]=p41.capacitiveSensor(resolution); 221 raw[42]=p42.capacitiveSensor(resolution); 222 223 raw[43]=p43.capacitiveSensor(resolution); 224 raw[44]=p44.capacitiveSensor(resolution); 225 226 raw[45]=p45.capacitiveSensor(resolution); 227 228 raw[46]=p46.capacitiveSensor(resolution); 229 230 raw[47]=p47.capacitiveSensor(resolution); 231 raw[48]=p48.capacitiveSensor(resolution); 232} 233 234 235void 236 data_process() 237{ 238 239float avg,max_val,tt1,tt2; 240int max_ind; 241int bend_base; 242avg=0;max_val=0;max_ind=0;tt1=0;tt2=0; 243 244 245for(int 246 i=1;i<49;i++) {avg=avg+raw[i];} 247avg=avg/48; 248 249for(int i=1;i<49;i++) 250{raw[i]=raw[i]-avg;} 251 252 253for(int 254 i=1;i<49;i++){if(raw[i]>max_val){max_ind=i; max_val=raw[i];}} 255 256for(int i=30; 257 i>0; i--) 258{ 259 key[i]=key[i-1]; 260 pressure[i]=pressure[i-1]; 261 play_stat[i]=play_stat[i-1]; 262} 263 264key[0]=(raw[max_ind-1]*(max_ind-1)+raw[max_ind]*(max_ind)+raw[max_ind+1]*(max_ind+1))/(raw[max_ind-1]+raw[max_ind]+raw[max_ind+1]); 265pressure[0]=raw[max_ind];//(raw[max_ind]+raw[max_ind-1]+raw[max_ind+1])/3; 266//Serial.println(raw[max_ind]); 267//Serial.println(pressure[0]); 268 269 270 271if(raw[max_ind]>=17){play_stat[0]=1;} 272 else{play_stat[0]=0;} // the value 17 decided by trial and error. 273//Serial.println(key[0]); 274 275if(play_stat[0]==1 276 && play_stat[1]==0) 277 {for(int i=0;i<15;i++) 278 { 279 key[i]=key[0]; 280 281 } 282 exp_smooth(); 283 play_note=play_acc; 284 285 if(play_acc-play_note>0.5){play_note=play_note+1;} 286 bend_base=512*(play_acc-play_note); 287 288 MIDImessage(144, play_note, velocity); 289 //Serial.print("ON");Serial.print("\ 290"); 291 292 } 293 294 295if(play_stat[0]==0 && play_stat[1]==1) 296 {MIDImessage(144, 297 play_note, 0); 298 //Serial.print("OFF");Serial.print("\ 299"); 300 } 301 302 303if(play_stat[0]==1) 304 { 305 exp_smooth(); 306 play_bend=8192+512*(play_acc-play_note)-bend_base; 307 308 if(play_bend>16384){play_bend=16383;} 309 if(play_bend<0){play_bend=0;} 310 311 play_at=play_pressure; 312 if(play_at>127){play_at=126;} 313 MIDImessage(224,(play_bend&127),(play_bend>>7)); 314 315 MIDImessage(208, 0, play_at); //253 316 //Serial.print(play_at);Serial.print("\ ");Serial.print(play_acc);Serial.print("\ ");Serial.print(play_note);Serial.print("\ ");Serial.print(play_bend);Serial.print("\ 317"); 318 319 320 } 321 322//Serial.println(play_at); 323/* 324Serial.print(play_note); 325Serial.print("\ "); 326Serial.print(play_stat[0]); 327Serial.print("\ "); 328Serial.print(play_acc); 329Serial.print("\ "); 330Serial.print(play_bend); 331Serial.print("\ "); 332Serial.print(play_pressure); 333Serial.print("\ "); 334Serial.print(max_val); 335Serial.print("\ "); 336*/ 337} 338 339 340void 341 exp_smooth() 342{ 343 play_acc=0; 344 play_pressure=0; 345 for(int 346 i=0; i<10; i++) 347 { 348 play_acc=play_acc+exp_data[i]*key[i]; 349 350 play_pressure=play_pressure+exp_data[i]*pressure[i]; 351 } 352 353 play_acc=54.25+play_acc/(2*exp_total); 354 play_acc=play_acc-1; 355 356 play_pressure=play_pressure/exp_total; // scalling to match 127 357} 358 359 360void 361 MIDImessage(int command, int data1, int data2) { 362 Serial.write(command);//send 363 command byte 364 Serial.write(data1);//send data byte #1 365 Serial.write(data2);//send 366 data byte #2 367}
Downloadable files
Wiring for plates
Wiring for plates
Wiring for plates
Wiring for plates
Comments
Only logged in users can leave comments
Anonymous user
3 years ago
Hello, There is a code error in the program: #include <CapacitiveSensor.h> What is the correct programming code? Thank you for your reply.