Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********** Proyecto ***********/
- const int notes=6; // set up number of notes
- boolean notePlaying[notes]; //note states array: keeps track of whether a MIDI note is "on" or "off"
- int scale[notes]={0,2,4,5,7,9}; //major scale
- int beginNote=0x3C; //starting note value (default middle C)
- int threshold=512; //value which analogRead() must cross for a midi note to be triggered
- boolean midiMode=false; //set this to "true" before uploading MIDI firmware (http://hunt.net.nz/users/darran/weblog/52882/Arduino_UNO_MIDI_USB_version_02.html) to 16u2
- void setup(){
- if(midiMode){
- Serial.begin(115200); //midi USB baud rate = 115200
- }else{
- Serial.begin(9600); //for testing values
- }
- }
- void loop() {
- for(int i=0;i<notes;i++){
- if((analogRead(i)<threshold)&&(notePlaying[i]==false)){ //note on & CC messages
- int note=beginNote+scale[i];
- midiMessage(0x90, 1, note, 100);
- notePlaying[i]=true;
- }
- if((analogRead(i)>threshold)&&(notePlaying[i]==true)){ //note off messages
- int note=beginNote+scale[i];
- midiMessage(0x80, 1, note, 0x00);
- notePlaying[i]=false;
- }
- }
- //Serial.println(analogRead(A5));
- //delay(400);
- }
- void midiMessage(int commandByte, int channelByte, int data1Byte, int data2Byte) {
- if(midiMode){
- Serial.write(commandByte);
- Serial.write(channelByte);
- Serial.write(data1Byte);
- Serial.write(data2Byte);
- }else{
- if(commandByte==0x90){
- Serial.print("Note On message: note ");
- }else if(commandByte==0x80){
- Serial.print("Note Off message: note ");
- }
- Serial.print(data1Byte);
- Serial.print(", velocity ");
- Serial.println(data2Byte);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement