#include <Encoder.h>
// PID parameters
#include "ArduPID.h"
ArduPID myController;
double input;
double output;
// Arbitrary setpoint and gains - adjust these as fit for your project:
double setpoint = 0;
double p = 5;
double i = 0;
double d = 0;
// Change these pin numbers to the pins connected.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
// avoid using pins with LEDs attached
// Encoder library parameters, pin numbers
Encoder knobLeft(2, 4);
void setup() {
Serial.begin(9600);
myController.begin(&input, &output, &setpoint, p, i, d);
myController.reverse();
myController.setOutputLimits(-100, 100);
myController.setSampleTime(10); // OPTIONAL - will ensure at least 10ms have past between successful compute() calls
//myController.setBias(100 / 1.0);
//myController.setWindUpLimits(-10, 10); // Groth bounds for the integral term to prevent integral wind-up
myController.start();
}
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
input = newLeft; // Replace with sensor feedback
myController.compute();
Serial.print("Input ");
Serial.print(input);
Serial.print(", Output ");
Serial.print(output);
Serial.println();
analogWrite(3, output); // Replace with plant control signal
}