Added write_pin function.