/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: Temperature Monitor
- Source Code NOT compiled for: ESP32 DevKit V1
- Source Code created on: 2024-09-20 09:58:11
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* afficher la température sur un tft LCD 3.5" ainsi */
/* qu'un curseur pour générer une alarme température */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // https://github.com/matmunk/DS18B20
#include // TFT library for 3.5" LCD
#include // SPI library for communication with TFT
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t DS18B20_DQ_PIN = 4; // Changed the variable name to a valid identifier
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an instance of the DS18B20 class, passing the digital pin number as a parameter
DS18B20 ds(DS18B20_DQ_PIN);
// Create an instance of the TFT display
TFT_eSPI tft = TFT_eSPI(); // Invoke library
/****** ALARM THRESHOLDS *****/
#define LOW_ALARM 20
#define HIGH_ALARM 25
void setup(void)
{
// Initialize serial communication for debugging
Serial.begin(9600);
// Set the pin mode for the DS18B20 data pin
pinMode(DS18B20_DQ_PIN, INPUT);
// Initialize the TFT display
tft.init();
tft.setRotation(1); // Set the rotation of the display
tft.fillScreen(TFT_BLACK); // Clear the screen with black color
tft.setTextColor(TFT_WHITE); // Set text color to white
tft.setTextSize(2); // Set text size
// Define the address of the DS18B20 sensor (replace with your actual sensor address)
uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
// Select the DS18B20 sensor using its address
if (ds.select(address)) {
// Set the alarm thresholds for the temperature
ds.setAlarms(LOW_ALARM, HIGH_ALARM);
} else {
Serial.println("Device not found!");
}
}
void loop(void)
{
// Define the address of the DS18B20 sensor (should match the address used in setup)
uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
// Check if the DS18B20 sensor is selected
if (ds.select(address)) {
// Get the current temperature
float temperature = ds.getTempC();
// Display the temperature on the TFT
tft.fillRect(0, 0, 240, 40, TFT_BLACK); // Clear previous temperature display
tft.setCursor(10, 10); // Set cursor position
tft.print("Temperature: ");
tft.print(temperature);
tft.println(" C");
// Check if the temperature alarm has been triggered
if (ds.hasAlarm()) {
// Print a warning message with the current temperature
Serial.print("Warning! Temperature is ");
Serial.print(temperature);
Serial.println(" C");
// Display alarm message on the TFT
tft.setTextColor(TFT_RED); // Set text color to red for alarm
tft.setCursor(10, 30); // Set cursor position for alarm message
tft.print("ALARM! Temp: ");
tft.print(temperature);
tft.println(" C");
}
} else {
Serial.println("Device not found!");
}
// Wait for 10 seconds before the next loop iteration
delay(10000);
}
/* END CODE */