Go Down

Topic: Usb Shield and Midi (Read 34 times) previous topic - next topic

antoniodna87

Hi! I realize wireless project by this -> http://www.youtube.com/watch?v=Nz_j3HVF4Ow

This is the code for RX:

Code: [Select]

#include <VirtualWire.h>
#include <SPI.h>
#include <Usb.h>
#include <usbhub.h>
#include <usbh_midi.h>

USB Usb;
USBH_MIDI Midi(&Usb);

byte PatchA1 = 0x28;
byte PatchA2 = 0x2C;
byte PatchB1 = 0x29;
byte PatchB2 = 0x2D;
byte PatchC1 = 0x2A;
byte PatchC2 = 0x2E;
byte PatchD1 = 0x2B;
byte PatchD2 = 0x2F;
byte Bypass  = 0x30;

#define LED 3
 
void setup() {
 pinMode(LED,OUTPUT);
 Serial.begin(9600);
 vw_set_rx_pin(2);
 vw_set_ptt_inverted(true);
 vw_setup(800);
 vw_rx_start();
 
 if(Usb.Init() == -1)
 while(1);
 delay(200);
}
 
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
 
 if (vw_get_message(buf, &buflen)) {
      digitalWrite(LED,HIGH);
      delay(20);
      digitalWrite(LED,LOW);
     
      if(buf[0]=='0') {
      Serial.println("bypass");
      SendMIDI(Bypass);
      }
        if(buf[0]=='1') {
        Serial.println("preset1");
        SendMIDI(PatchA1);
        }
          if(buf[0]=='2') {
          Serial.println("preset2");
          SendMIDI(PatchB1);
          }
            if(buf[0]=='3') {
            Serial.println("preset3");
            SendMIDI(PatchC1);
            }
              if(buf[0]=='4') {
              Serial.println("preset4");
              SendMIDI(PatchD1);
              }
                if(buf[0]=='5') {
                Serial.println("preset5");
                SendMIDI(PatchA2);
                }
                  if(buf[0]=='6') {
                  Serial.println("preset6");
                  SendMIDI(PatchB2);
                  }
                    if(buf[0]=='7') {
                    Serial.println("preset7");
                    SendMIDI(PatchC2);
                    }
                      if(buf[0]=='8') {
                      Serial.println("preset8");
                      SendMIDI(PatchD2);
                      }
 }
}

void SendMIDI(byte number) {
  Usb.Task();
  if(Usb.getUsbTaskState() == USB_STATE_RUNNING) {
    byte Message[2];               
    Message[0]=0xC0;               
    Message[1]=number;             
    Midi.SendData(Message);         
    delay(10);
  }
}


So I receive and transmit perfectly but now I have 2 problems:

  • When I turn on the TX and RX, the transmission is not immediatly... I push the button (on TX) for select the preset many times, after the communication is perfectly and all works fine. This problem is caused by Usb Host Shield (maybe), because the expression Usb.getUsbTaskState() == USB_STATE_RUNNING is not true immediatly. Can I solve this problem???
  • When I turn on the Zoom ms70cdr, the display don't show memory (default) but effect and I must go manually in memory. If I don't follow this procedure all system (maybe your too) don't work. Can I display zoom memory on startup?


Tnk in advance... Bye

Go Up