/**
Basic NTC Thermistor demo
https://wokwi.com/arduino/projects/299330254810382858
Assumes a 10K@25℃ NTC thermistor connected in series with a 10K resistor.
Copyright (C) 2021, Uri Shaked
*/
#include <TFT.h>
#include <SPI.h>
#define CS 10
#define DC 9
#define RESET 8
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
TFT screen = TFT(CS, DC, RESET);
float currentAverage;
int counter;
int tempSum;
// char array to print time
char printoutC[8];
char printoutA[8];
void setup() {
currentAverage = 0;
counter = 0;
tempSum = 0;
screen.begin();
screen.setTextSize(1.5);
screen.background(0, 0, 0); // clear the screen
screen.stroke(255, 255, 255);
// static text
screen.text("Current Temperature", 0, 0);
screen.text("C", 155, 0);
screen.text("Average Temperature", 0, 40);
screen.text("C", 155, 40);
}
void loop() {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
counter = counter + 1;
tempSum = tempSum + celsius;
if ((counter % 10) == 0) {
currentAverage = tempSum / counter;
}
String average = String(currentAverage);
average.toCharArray(printoutA, 8);
String current = String(celsius);
current.toCharArray(printoutC, 8);
screen.stroke(255, 255, 255);
screen.text(printoutC, 125, 0);
screen.text(printoutA, 125, 40);
delay(1000);
screen.stroke(0, 0, 0);
screen.text(printoutC, 125, 0);
screen.text(printoutA, 125, 40);
}