Using arduino's PID library in a class....

Thread Starter

Gibson486

Joined Jul 20, 2012
355
I am trying to use Arduino's PID library in a class I made. Does this look it would work? Every time I look this up, they say to extend and use a virtual class, but that seems more complex than it needs to be.

Would this not work?

Code:
class Control{
   
    private:
   
     //private variables
   
    public:
    Control()
    {
        double Setpoint, Input, Output;
       
        PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
    }

   //rest of my public functions to access private variables
};
 

Thread Starter

Gibson486

Joined Jul 20, 2012
355
Got it to compile. Fingers crossed it will work as intended when I upload it!

Code:
class Control{
  
    private:
  
     //private variables
     PID* myPID;
  
    public:
    Control()
    {
        //all private variables defined to something
      
        myPID = new PID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
    }
   //rest of my public functions to access private variables
};
 
Top