The function of the camshaft is to precisely control the opening and closing of the valves through its high-precision cam profiles, in accordance with the engine's operating cycle and firing order. This enables accurate management of the engine's intake and exhaust processes, ensuring efficient engine operation.