Ecco il sorgente incriminato...
/*
Stove's regulator - Regolatore di ventilazione per stufe ad accumulo. - 08/2010 MfN
legge la temperatura dei fumi tramite termocoppia (MAX6675)
in base alla temperatura, regola la ventilazione tramite servo
visualizza sul display temperatura e c.
*/
#include <LiquidCrystal.h>
#include <MAX6675.h>
#include <buttons.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <Servo.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int CS = 8; // CS pin on MAX6675
int SO = 9; // SO pin of MAX6675
int SCK = 10; // SCK pin of MAX6675
int units = 1; // Units to readout temp (0 = ?F, 1 = ?C)
float error = 0.0; // Temperature compensation error
float temp = 0.0; // Temperature output variable
// Initialize the MAX6675 Library for our chip
MAX6675 temp0(CS,SO,SCK,units,error);
Button A;
Button B;
// posizioni servo
Servo serv1;
int MAX_chiuso=180;
int MAX_aperto=1;
// soglie temperatura in gradi centigradi
int temp_lim0=90; // tutto chiuso (perc_ap0)
int temp_lim1=100; //
int temp_lim2=200;
int temp_lim3=300;
int temp_lim4=400; // tutto aperto
float perc_ap;
int perc_ap0=0; // tutto chiuso
int perc_ap1=40;
int perc_ap2=75;
int perc_ap3=85;
int perc_ap4=100; // tutto aperto
int alfa; //angolo di lavoro
int stato;
int pos;
float pos_r;
float incr_r = 0.1;
int avvio; // stato del regolatore: 1=avvio stufa, 0= normale
void leggi_temp() {
float t;
t = temp0.read_temp(9); // Read the temp 5 times and return the average value to the var
Serial.println(t);
temp = t;
}
void setup() {
A.assign(12); // inizializzazione pulsanti
B.assign(13);
A.setMode(4);
B.setMode(4);
Serial.begin(115200);
serv1.attach(11,1000,2050);
Alarm.timerRepeat(1, leggi_temp);
Serial.println("set");
lcd.begin(16, 2);
}
void loop() {
lcd.setCursor(0, 1);
// temp = temp0.read_temp(9); // Read the temp 5 times and return the average value to the var
Serial.println("loop");
if(temp == -1) { // If there is an error with the TC, temperature will be -1
lcd.setCursor(0, 1);
lcd.print("Errore termocoppia !"); // Temperature is -1 and there is a thermocouple error
}
else {
lcd.setCursor(0, 1);
lcd.print("C ");
lcd.print( temp ); // Print the temperature to Serial
}
delay(500);
// calcolo posizione
alfa=MAX_aperto-MAX_chiuso; //angolo operativo
if (temp<temp_lim0) {
perc_ap=0;
}
....
Come vedi, ho messo degli output sulla seriale per tracciare il running su Arduino: viene eseguita la "setup", la "loop" è eseguita regolarmente, ma la "leggi_temp" non viene eseguita MAI... ma viene compilata regolarmente, e gli eventuali errori sintattici vengono rilevati dal compilatore...
(non è codice definitivo, ne manca ancora un bel pezzo...)