Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- PID Basic Example
- Reading analog input A1 to control analog PWM output 3
- */
- #include <PID_v1.h>
- const byte PIN_INPUT = A1;
- const byte PIN_OUTPUT = 3;
- //Define Variables we'll be connecting to
- double Setpoint, Input, Output;
- // parameters
- double Kp=2, Ki=5, Kd=1;
- PID myPID(Input, Output, Setpoint, Kp, Ki, Kd);
- void setup()
- {
- //initialize the variables we're linked to
- Input = analogRead(PIN_INPUT);
- Setpoint = 100;
- //turn the PID on
- myPID.SetMode(AUTOMATIC);
- }
- void loop()
- {
- Input = analogRead(PIN_INPUT);
- myPID.Compute();
- analogWrite(PIN_OUTPUT, Output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement