Our teacher while explaining first law of thermodynamics showed us an example of a piston inside a chamber. He said when heat is applied the particles move, i.e the kinetic energy increases. Due to this velocity the molecules put some pressure on piston. Due to which the piston moves.
He said that some part of the energy supplied (heat) goes in increasing kinetic energy and other in doing work due to which the piston moves.
$$ dQ= dU + dW $$
My doubt is that how is the heat affecting the pressure applied directly. The heat affects the velocity of gas molecule which then increases the pressure on piston due to which it moves.
He also said that if there was no piston then the total heat will go into increase in kinetic energy. Which doesn't make sense how does the heat or molecules know when to take some energy when when to not?
But how is heat directly effecting the work done? I believe that heat goes fully in to vibrating/increasing kinetic energy of particle.