processing accelerometer data x, y, z, a
Hi, I have 4 streams of data coming into max from a micro bit. They come through the serial port as, for example, "x:678" [new print line] "y:34" [new print line] "z:354" [new print line] "a:1024".
Currently I am using zl group to form a list of ascii numbers for each of the print lines. I've tried a few different ways to then separate the symbols from the numbers, so that I can put the numbers into sliders, but nothing is quite right.
eg, in the current example, when I unpack the ascii code, lose the symbols and then repack the digits, I am getting some really odd readings because if, as in the example screen shot below, the number 1022 is followed by 848, the pack is still sending 4 digits instead of just the new 3 digits, so the last 2 is tagged onto the end (at least that's what I think is happening). So, maybe a way to flush the pack clear each time it's used would solve this?
A more elegant solution would be to ask of the incoming data "which axis are these digits assigned to: x, y, z or a?" and then syphon off just the numerical data into an x, y, z or a slider.
I've attached the patch, but I guess you need to be running the micro bit to get it working, so screenshots also attached.
Any ideas?
Thanks
Don't use unpack / pack.
pack allways outputs all members of the list no matter what the input is.
zl slice 2 would do to remove x: or z:
or better route 4 chars to output :
Thanks Source Audio. I had eventually used zl slice 2, which works ok, but I didn't know about sprintf and that does exactly what I was looking for. Thanks for your help and the patch.
Sprintf is just to simulate input from serial port.
The regexp is the key as it replaces : with space
allowing route x y z a to route the values.