Final MATLAB code

This code is not perfect. The lag could be reduced by using a different type of encoding (instead of decimal), and by looking into the pause command.  I am not sure it is optimized or even necessary. However, it works for our purposes.