Unas recomendaciones adicionales.
Imagino que tienes dos pulsadores entre GND y pin 2 y 3 respectivamente. Usa el flanco de subida (RISING) que es cuando sueltas el boton que controla mejor porque solo hay uno por pulsacion.
//Interrupciones
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
attachInterrupt(0, distemp, RISING);
attachInterrupt(1, aumtemp, RISING);
Con esto ya no necesitas controlar el tiempo de la presión del pulsador:
void distemp(){
tref-- ;
flag = true;
}
void aumtemp(){
tref++ ;
flag = true;
}
Hay otro tema que me preocupa y es que no se si Setpoint se entera del cambio en tref. Yo mejor me aseguraria asi:
//Cambio en tref (interrupcion)
if (flag) {
Setpoint = tref;
EEPROM.write(Direccion, tref);
flag = false;
delay(10);
}
PD: Este es un proyecto real o solo un ejercicio para entender la libreria PID ? En otras palabras ya probaste el método simple con un if() y no te funciono ?