Skip to content

Commit c7bc39f

Browse files
Create PIDSimpleExample.ino
1 parent 8ea5031 commit c7bc39f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "PIDEasy.h"
2+
3+
PID lineFollower(1.0, 0.0, 0.0); // Kp, Ki, Kd
4+
5+
int error = 0;
6+
const int setPoint = 10;
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
lineFollower.setConstrain(-100, 100); // set Constrain for output of PID
11+
lineFollower.setWindUP(-100, 100); // set Constrain for Integral
12+
}
13+
14+
void loop() {
15+
int measurement = analogRead(A0); // Sensor Measurement
16+
error = measurement - setPoint; // calculate the error
17+
float output = lineFollower.compute(error, 1); // (error, dt), if do you not want to use dt only put 1 in parameter.
18+
19+
Serial.println("Output: " + String(output)); // Print the output
20+
}

0 commit comments

Comments
 (0)