Hi Marco,
The "PID2" library can be found here: MartinL1 · GitHub.
To call the PID2 class constructor:
PID myPID;
To initialise the PID controller's gains plus integral and output limits, (all arguments are float data types):
myPID.begin(kp, ki, kd, iMinLimit, iMaxLimit, pidMinLimit, pidMaxLimit);
To compute the PID output:
float pidOutput = myPID.pidCalculate(setpoint, input, dt);
where "dt" is the sample time in seconds.
The sample time "dt" is calculated as follows:
uint32_t timeMicros = micros();
dt = (timeMicros - lastTime) / 1.0e6f;
lastTime = timeMicros;
where "lastTime" is a uint32_t data type and "dt" is a float.
On the Arduino Nano this gives you a sample time accurate to 4 microseconds.