Declare a variable to control the sample rate of the PID control. This means that the control occurs at regular intervals and can be tuned for the application.
During the Arduino setup() function the initial input and set point to the controller should be assigned. The SetMode() function can be set to “AUTOMATIC” to turn on the PID control, or it can be set to “MANUAL” to give you control of the controller output. At this point the sample rate can be set through the SetSampleTime() function.
During the Arduino loop() function we probably want to now dynamically assign the set point and the input. The PID compute() function can then be called and the output value assigned to the actuator.