Adapted as a library for Arduino 1.x