// PORTA = D29, D28 ... D22 (msb -> lsb)
// G A
volatile int i = 0;
byte cifra[10] = {0b11000000, 0b11111001, 0b10100100, 0b10110000,
0b10011001, 0b10010010, 0b10000010, 0b11111000, 0b10000000, 0b10010000};
byte multiplexare[4] = {0B00000001, 0B00000010, 0B00000100, 0B00001000};
char th1 = A0, th2 = A1;
int read1 = 0;
volatile bool thCitit = true;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup(){
DDRA = 0B11111111;
DDRD = 0B11111111;
cli();
TCCR1A = 0;
TCCR1B = 0;
OCR1A = 2550;
TCCR1B |= 0B00001101;
TIMSK1 |= (1 << OCIE1A);
TCCR2A = 0;
TCCR2B = 0;
OCR2A = 255;
TCCR2B |= 0B00000111;
TCCR2A |= 0B10000010;
TIMSK2 |= (1 << OCIE2A);
sei();
pinMode(th1, INPUT);
pinMode(th2, INPUT);
}
void loop(){
if(thCitit){
read1 = getTemp(th2);
}else{
read1 = getTemp(th1);
}
Serial.println(thCitit);
afisare();
}
void afisare(){
if(read1 < 0 || read1 > 100){
PORTA = 0b10111111;
}
else{
switch(i){
case 0: PORTA = cifra[(read1 /1000) % 10];
break;
case 1: PORTA = cifra[(read1 /100) % 10];
break;
case 2: PORTA = cifra[(read1 /10) % 10];
break;
case 3: PORTA = cifra[read1 % 10];
}
}
PORTD = multiplexare[i];
}
ISR(TIMER1_COMPA_vect){
i = (i + 1) % 4;
}
int getTemp(int r){
int analogValue = analogRead(r);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
return round(celsius);
}
ISR(TIMER2_COMPA_vect){
thCitit = !thCitit;
}