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.72 KB | None | 0 0
  1. /********************************************************
  2.  * PID Basic Example
  3.  * Reading analog input A1 to control analog PWM output 3
  4.  ********************************************************/
  5.  
  6. #include <PID_v1.h>
  7.  
  8. const byte PIN_INPUT = A1;
  9. const byte PIN_OUTPUT = 3;
  10.  
  11. //Define Variables we'll be connecting to
  12. double Setpoint, Input, Output;
  13.  
  14. // parameters
  15. double Kp=2, Ki=5, Kd=1;
  16. PID myPID(Input, Output, Setpoint, Kp, Ki, Kd, DIRECT);
  17.  
  18. void setup()
  19. {
  20.   //initialize the variables we're linked to
  21.   Input = analogRead(PIN_INPUT);
  22.   Setpoint = 100;
  23.  
  24.   //turn the PID on
  25.   myPID.SetMode(AUTOMATIC);
  26. }
  27.  
  28. void loop()
  29. {
  30.   Input = analogRead(PIN_INPUT);
  31.   myPID.Compute();
  32.   analogWrite(PIN_OUTPUT, Output);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement