Go Down

Topic: Traktor to MiniArduino (Read 500 times) previous topic - next topic

Javierosu

Hello,

I have a problem receiving Midi from Traktor.
The entire system seems to communicate, the different bytes of the notes switch modes when sending the byte slowly, but it seems that the high number of packages sent from Traktor confuses my system and misses some of them, also seeming faulty.

I am using the last version of MIDI library. Here is my codeƑ

Code: [Select]
#include <SD.h>
#include <MIDI.h>
#include <Adafruit_NeoPixel.h>
#define PIXELS 162
#define led 13
#define PIN 7
long time;
long timeOffset=0; // tells program when animation started playing
File myFile;
int fileSize;
int scan=0;
int frameNum;
int frameCount;
long frameLast=0;
float frameRate;
int maxbright=10;
char name[]="f00.bin";
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup(){
  int fileSize;
  pinMode(led,OUTPUT);
  MIDI.begin(MIDI_CHANNEL_OMNI);
  MIDI.setHandleNoteOn(HandleNoteOn);
  MIDI.setHandleNoteOn(HandleNoteOff);
  pinMode(10, OUTPUT);
  SD.begin(10);
  strip.begin();
}
void loop(){
  MIDI.read();
  time=millis()-timeOffset;
  play();
}
void printImage(int frame, char name[]) {
  uint8_t buf[3];
  uint32_t pixelcol;
  myFile = SD.open(name);
  if(myFile){
    fileSize=myFile.size();
    frameCount=fileSize/250;
    myFile.seek(frame*250);
    for(int i=0; i<(PIXELS/2); i=i++){
      for(int j=0; j<3; j++){
        buf[j]=myFile.read();
      }
      pixelcol=((uint32_t)(buf[0]&B00001111)<<12)|((uint32_t)(buf[1]&B11110000))|((uint32_t)(buf[0]&B11110000)<<16);
      strip.setPixelColor(i*2, pixelcol);
      pixelcol=((uint32_t)(buf[2]&B00001111)<<4)|((uint32_t)(buf[2]&B11110000)<<8)|((uint32_t)(buf[1]&B00001111)<<20);
      strip.setPixelColor(i*2+1, pixelcol);
    }
    myFile.close();
  }
  else {
    black();
    for(int i=0; i<3; i++){
    digitalWrite(led,HIGH);
    delay(100);
    digitalWrite(led,LOW);
    delay(100);
    }
  }

}
char getFilename(char *filename, int num){
  filename[1]=num/10+'0';
  filename[2]=num%10+'0';
}
void printVideo(char name[]){
  printImage(frameNum, name);
  frameNum++;
  if(frameNum>(frameCount-1)){
    frameNum=0;
  }
}



And for switching the modes:
Code: [Select]
int mode=0;
byte pitches[] = {
  60,62,64,65,67,69,71,72,74};
void play(){
  switch(mode){
  case 0:
    black();
    break;
  case 1:
    colorWipe(strip.Color(255, 0, 0), 1000);
    break;
  case 2:
    colorWipe(strip.Color(0, 255, 0), 1000);
    break;
  case 3:
    colorWipe(strip.Color(0, 0, 255), 1000);
    break;
  case 4:
  getFilename(name,1);
    printImage(0,name);
    break;
  default:
    black();
    break;
  }
  strip.show();
}
void HandleNoteOn(byte channel, byte pitch, byte velocity)
{
  switch(pitch){
  case 60:
    mode=0;
    break;
  case 62:
    mode = 1;
    break;

  default:
    mode = -1;
    break;
  }
  timeOffset=millis();
}
void HandleNoteOff(byte channel, byte pitch, byte velocity)
{
  mode=0;
}


Do you have any suggestion? My mate and me have spent a long time and we have been unable to solve the issue.

Thank you so much!

Go Up