Here is a document by George Gillard that goes over the basics of a PID control loop with pseudocode
And here is an example P loop in vexcode c++