converting to Arduino library

Is this closer to the Arduino library you wanted?