I use analogWrite(DAC1,Output) in my code, but I find it like digital pulse output, rather than expected analog continuous curve, i don't know why, forgive a fresh people in C language.
#include<PID_v1.h>
double Setpoint, Input, Output;
PID myPID(&Input,&Output,&Setpoint,2,5,30,DIRECT);
void setup()
{
Input= analogRead(A0);
Setpoint = 3000;
Serial.begin(9600);
myPID.SetMode(AUTOMATIC);
myPID.SetSampleTime(10);
// put your setup code here, to run once:
}
void loop() {
Input = analogRead(A0);
Serial.print("Input = ");
Serial.println(Input);
myPID.Compute();
analogWrite(DAC1,Output);
Serial.print("Output = ");
Serial.println(Output);
// put your main code here, to run repeatedly:
}
The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs.