Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. /*
  2.  PID Basic Example
  3.  Reading analog input A1 to control analog PWM output 3
  4. */
  5. #include <PID_v1.h>
  6. const byte PIN_INPUT = A1;
  7. const byte PIN_OUTPUT = 3;
  8. //Define Variables we'll be connecting to
  9. double Setpoint, Input, Output;
  10. // parameters
  11. double Kp=2, Ki=5, Kd=1;
  12. PID myPID(Input, Output, Setpoint, Kp, Ki, Kd);
  13.  
  14. void setup()
  15. {
  16.   //initialize the variables we're linked to
  17.   Input = analogRead(PIN_INPUT);
  18.   Setpoint = 100;
  19.   //turn the PID on
  20.   myPID.SetMode(AUTOMATIC);
  21. }
  22.  
  23. void loop()
  24. {
  25.   Input = analogRead(PIN_INPUT);
  26.   myPID.Compute();
  27.   analogWrite(PIN_OUTPUT, Output);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement