Modified to work with SmartMatrix library without Daniel's changes