Hi all,
I'm trying to get data flowing between my DJ Hero and Arduino / Processing, so I can produce MIDI messages for Traktor. I've based my work on a library by Jason Leyrer which does the same thing for a Guitar Hero controller, and I hope to make my version a plug-and-play library for Arduino users with a DJ Hero controller.
I've already had some great help from Nick Gammon of this forum on arduino.stackexchange but I'm stuck again; I'm really not very experienced with all this bit-level stuff.
I have everything connected as follows:
DJ Hero controller Arduino Mega Processing Traktor software.
What I now have in the Arduino (thanks to Nick) is a nicely formatted union which equates to the six bytes of data that I'm reading from the DJ Hero.
However I'm not sure what is the best approach to send this data structure into Processing. Is it possible to send as a six-byte packet? Should I just be accessing the union's fields by name on Arduino, outputting name: value
to Serial and parsing that in Processing?
Right now my output looks like this:
-- packedFields bytes --
100000
1001110
10001110
1110
0
11111111
-------------------
I think I get why each representation of a byte isn't 8-bits long (because I'm casting from Int
?), but how do I get each byte into Processing intact?
I tried casting out to char
and got this:
-- packedFields bytes --
100000
1001110
11111111111111111111111110001110
1110
0
11111111111111111111111111111111
-------------------
So now I am back to casting to int
, then printing to Serial. The command I'm using for this is Serial.println((int) theFields.b [i], BIN);
I tried a simple bit of testing using the following code:
unsigned int oneBit = 1;
if(theFields.b.rbb == oneBit){
Serial.print("Blue pressed");
}
if(theFields.b.rbg == oneBit){
Serial.print("Green pressed");
}
if(theFields.b.rbr == oneBit){
Serial.print("Red pressed");
}
But this produces the following error:
error: request for member 'rbb' in 'theFields.packedFieldsUnion::b', which is of non-class type 'uint8_t [6] {aka unsigned char [6]}
TBH I've been at this for over a week and really just want to get on with the DJing (this is all for a friend's wedding I'm playing in September); I'd really appreciate some help on getting this up and running!
Full code attached
DJ_Hero_on_Mega.zip (56.8 KB)