Components and supplies
Arduino Mega 2560
Project description
Code
Pianographe
arduino
1int val = 0; //Our initial pot values. We need one for the first value and a second to test if there has been a change made. This needs to be done for all 3 pots. 2int lastVal = 0; 3int val2 = 0; 4int lastVal2 = 0; 5int val3 = 0; 6int lastVal3 = 0; 7int val4 = 0; 8int lastVal4 = 0; 9int val5 = 0; 10int lastVal5 = 0; 11int val6 = 0; 12int lastVal6 = 0; 13int val7 = 0; 14int lastVal7 = 0; 15int val8 = 0; 16int lastVal8 = 0; 17int val9 = 0; 18int lastVal9 = 0; 19int val10 = 0; 20int lastVal10 = 0; 21int val11 = 0; 22int lastVal11 = 0; 23int val12 = 0; 24int lastVal12 = 0; 25 26void setup() 27{ 28 Serial.begin(9600); // Set the speed of the midi port to the same as we will be using in the Hairless Midi software 29} 30 31void loop() 32{ 33 val = analogRead(0)/8; // Divide by 8 to get range of 0-127 for midi 34 if (val != lastVal) // If the value does not = the last value the following command is made. This is because the pot has been turned. Otherwise the pot remains the same and no midi message is output. 35 { 36 MIDImessage(176,1,val);} // 176 = CC command (channel 1 control change), 1 = Which Control, val = value read from Potentionmeter 1 NOTE THIS SAYS VAL not VA1 (lowercase of course) 37 lastVal = val; 38 39 val2 = analogRead(1)/8; // Divide by 8 to get range of 0-127 for midi 40 if (val2 != lastVal2) 41 { 42 MIDImessage(176,2,val2);} // 176 = CC command, 2 = Which Control, val = value read from Potentionmeter 2 43 lastVal2 = val2; 44 45 val3 = analogRead(2)/8; // Divide by 8 to get range of 0-127 for midi 46 if (val3 != lastVal3) 47 { 48 MIDImessage(176,3,val3);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 49 lastVal3 = val3; 50 51 val4 = analogRead(3)/8; // Divide by 8 to get range of 0-127 for midi 52 if (val4 != lastVal4) 53 { 54 MIDImessage(176,4,val4);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 55 lastVal4 = val4; 56 57 val5 = analogRead(4)/8; // Divide by 8 to get range of 0-127 for midi 58 if (val5 != lastVal5) 59 { 60 MIDImessage(176,5,val5);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 61 lastVal5 = val5; 62 63 val6 = analogRead(5)/8; // Divide by 8 to get range of 0-127 for midi 64 if (val6 != lastVal6) 65 { 66 MIDImessage(176,6,val6);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 67 lastVal6 = val6; 68 69 val7 = analogRead(6)/8; // Divide by 8 to get range of 0-127 for midi 70 if (val7 != lastVal7) 71 { 72 MIDImessage(176,7,val7);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 73 lastVal7 = val7; 74 75 val8 = analogRead(7)/8; // Divide by 8 to get range of 0-127 for midi 76 if (val8 != lastVal8) 77 { 78 MIDImessage(176,8,val8);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 79 lastVal8 = val8; 80 81 val9 = analogRead(8)/8; // Divide by 8 to get range of 0-127 for midi 82 if (val9 != lastVal9) 83 { 84 MIDImessage(176,9,val9);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 85 lastVal9 = val9; 86 87 val10 = analogRead(9)/8; // Divide by 8 to get range of 0-127 for midi 88 if (val10 != lastVal10) 89 { 90 MIDImessage(176,10,val10);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 91 lastVal10 = val10; 92 93 val11 = analogRead(10)/8; // Divide by 8 to get range of 0-127 for midi 94 if (val11 != lastVal11) 95 { 96 MIDImessage(176,11,val11);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 97 lastVal11 = val11; 98 99 val12 = analogRead(11)/8; // Divide by 8 to get range of 0-127 for midi 100 if (val12 != lastVal12) 101 { 102 MIDImessage(176,12,val12);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3 103 lastVal12 = val12; 104delay(15); //here we add a short delay to help prevent slight fluctuations, knocks on the pots etc. Adding this helped to prevent my pots from jumpin up or down a value when slightly touched or knocked. 105} 106 107void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command 108{ 109 Serial.write(command); 110 Serial.write(data1); 111 Serial.write(data2); 112} 113
Comments
Only logged in users can leave comments
idioma
0 Followers
•0 Projects
Table of contents
Intro
20
0