#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,5,2,1, DIRECT); // 1
int potPin = A2; // select the input pin for the potentiometer
int pot = 0; // it starts as O but it's not necessary to define it, it doesn't change anything
int dir2B= 12; // Motor direction
int enableM2 = 10; // Motor enabling
void setup () // definine inputs and outputs
{
Serial.begin(9600);
pinMode(potPin, INPUT); // we define the potentiometer input
pinMode(dir2B, OUTPUT); // set the motor pins as outputs:
pinMode(enableM2, OUTPUT); // set the motor pins as outputs:
digitalWrite(enableM2, HIGH); // set enablePins high so that motor can turn on:
//initialize the variables we're linked to
Input = analogRead(potPin);
Setpoint = 586;
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop ()
{
pot= analogRead(potPin); // read the value of the potentiometer
Input = pot;
myPID.Compute();
int error=(586-pot); // reference=586, measured=pot
int vel=255;
if (-190 < error && error < 0) // if the value of the potentiometer is between -190 and 0 degrees:
{
digitalWrite(dir2B, HIGH);
analogWrite(enableM2,(255-Output));
Serial.println(255-Output);
}
if (190 > error && error > 0) // if the value of the potentiometer is between 190 and 0 degrees:
{
digitalWrite(dir2B, LOW);
analogWrite(enableM2,Output);
Serial.println(Output);
}
if (error < -190 || error > 190) // if the value of the potentiometer is less than -190 or more than 190 degrees:
{
digitalWrite(enableM2, LOW);
}
}
Errors:
C:\Users\Partha\Documents\Arduino\libraries\PID_v1\PID_v1.cpp: In constructor 'PID::PID(double*, double*, double*, double, double, double, int)':
C:\Users\Partha\Documents\Arduino\libraries\PID_v1\PID_v1.cpp:26: error: 'millis' was not declared in this scope
C:\Users\Partha\Documents\Arduino\libraries\PID_v1\PID_v1.cpp: In member function 'void PID::Compute()':
C:\Users\Partha\Documents\Arduino\libraries\PID_v1\PID_v1.cpp:43: error: 'millis' was not declared in this scope
If anyone can solve those Errors..Plss Tell me as soon as possible...