Serial – How to isolate bits from Arduino Input

May 9, 2010 at 3:40pm

Serial – How to isolate bits from Arduino Input

Hi,

I have built a foot pedal board to use with Ableton Live, so I am building a Max patch in Max4Live to record clips, trigger clips and overdub clips from my board. The board looks like this:

http://www.flickr.com/photos/matthewhubble/2380128212/in/photostream/

I will be using an Arduino to send messages via serial to Max. This is the protocol I have come up with (uses 8 bits):

Bit 0 – Mode switch 1 (Top button on far right of my board)
Bit 1 – Mode switch 2 (Bottom button on far right of my board)
Bit 2 through 4 – 3 bits to give Y axis position of button, 0, 1, or 2
Bits 5 through 7 – 3 bits to give X axis position of buton presses, 0, 1, 2, 3, 4, 5, or 6

I will send a newline character after each message so I know where a message begins and ends.

I need to isolate these individual bits and convert them to an integer in my Max patch so I can do something meaningful with them, all I can find is audio-rate bit operations, not what I want. Can anyone tell me what to do?

Also, how to I paste my patch I currently have in the forum? Can’t figure out how to that. Thanks

Attachments:
  1. Loop_Pedal.amxd
#50280
May 9, 2010 at 4:39pm

Post your Max patch by going: Edit Mode/Edit/Copy Compressed; then paste onto your post. A jpeg or other of your Arduino program would also help. Meanwhile look at the helpfile for the [zl] object (right/alt click on it). I access my Arduino serial ANALOG data by converting to ASCII and using the [select] object (select 255), but your BINARY ‘matrix-like’ data looks a little more complex than i usually run in to.

#180383
May 10, 2010 at 6:47pm

To isolate an individual bit, you just need to perform a logical AND with a mask number, eventually followed by a shift.

If you do an AND with 1, you’ll get the least significant bit state; if you use 2, you’ll get the next bit state.

To get bits 2-4, AND with 11100 , i.e. 28, and shift 2 bits to the right.

p

#180384

You must be logged in to reply to this topic.