Add state machine to device

Update the code on the Arduino side so that it implements a state
machine. Bytes are read one-by-one and interpreted based on the current
state.