Arduino-PID-Library/PID_v1/Examples/PID_Basic/PID_Basic.pde
Brett Beauregard 98d2779e18 Initial Commit To Git Hub
There are 3 changes:
 - All code changes will now be here instead of on Google Code
 - The license has been changed to GPLv3
 - Support for Arduino 1.0 was added
2011-12-14 07:20:47 -05:00

32 lines
638 B
Plaintext

/********************************************************
* PID Basic Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/
#include <PID_v1.h>
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
void setup()
{
//initialize the variables we're linked to
Input = analogRead(0);
Setpoint = 100;
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
Input = analogRead(0);
myPID.Compute();
analogWrite(3,Output);
}