#include <Encoder.h>
// PID parameters
#include "ArduPID.h"
ArduPID myController1;
ArduPID myController2;
double input1;
double output1;
double input2;
double output2;
// Arbitrary setpoint and gains - adjust these as fit for your project:
double setpoint = 20;
double p = 1;
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);
Encoder knobRight(3, 5);
void setup() {
Serial.begin(9600);
myController1.begin(&input1, &output1, &setpoint, p, i, d);
myController1.setOutputLimits(-255, 255);
myController1.start();
myController2.begin(&input2, &output2, &setpoint, p, i, d);
myController2.setOutputLimits(-255, 255);
myController2.start();
}
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
input1 = newLeft; // Replace with sensor feedback
input2 = newRight; // Replace with sensor feedback
myController1.compute();
myController2.compute();
Serial.print("Input1 ");
Serial.print(input1);
Serial.print(", Output1 ");
Serial.print(output1);
Serial.print(" Input12 ");
Serial.print(input2);
Serial.print(", Output2 ");
Serial.print(output2);
Serial.println();
analogWrite(10, output1); // Replace with plant control signal
analogWrite(11, output2); // Replace with plant control signal
}