Use This Code (In Celsius)
Use This Code (In Celsius)
////////////////////////////////////////////////
// iThermowall Thermometer Firmware //
// Celsius Modification //
////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
pinMode(statePin, INPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
pinMode(buzzer, OUTPUT);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(20, 20);
display.println("Initializing");
display.display();
delay(250);
display.clearDisplay();
mlx.begin(); //sensor initialization
void loop()
{
static float temperature = -1; //initial condition
if (measurement == true)
{
temperature = GetTemp(); //get temperature in Celsius
} else {
temperature = -1; //marker if sensor not reading temperature
}
float GetTemp()
{
static int index = 0;
static float temptot = 0;
float hasil = 0;
if (sensorDelay.justFinished())
{
sensorDelay.repeat(); // repeat
temptot += mlx.readObjectTempC(); // add the reading to the total
index++; // increment index
if(index == 19)
{
hasil = temptot / 20; // calculate average
temptot = 0; // reset total
index = 0; // reset index
sensorDelay.stop(); // stop reading
displayDelay.finish(); // complete the refresh interval so that it shows
immediately
return hasil; // return result
}
}
return hasil; // As long as there are no results, give a value of result = 0
}
void holdReading()
{
if (holdDelay.justFinished()) {
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, LOW);
digitalWrite(buzzer, LOW);
measurement = false;
displayDelay.start(interval_display); // restart the OLED display
}
}