Advertisement
pleasedontcode

Temperature Control rev_10

Jan 26th, 2025
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Temperature Control
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-01-26 10:18:22
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* 温度到达 60led亮灯 */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs();
  33. void readTemperature(); // Function to read temperature
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t ttt_DHT22_DOUT_PIN_D13        = 13;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t tt_LED_PIN_D4     = 4;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool    tt_LED_PIN_D4_rawData       = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float   tt_LED_PIN_D4_phyData       = 0.0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. // Create an instance of the DHT sensor
  51. DHT dht(ttt_DHT22_DOUT_PIN_D13, DHT22); // Assuming DHT22 sensor
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.     pinMode(ttt_DHT22_DOUT_PIN_D13, INPUT_PULLUP);
  57.     pinMode(tt_LED_PIN_D4, OUTPUT);
  58.    
  59.     dht.begin(); // Initialize the DHT sensor
  60. }
  61.  
  62. void loop(void)
  63. {
  64.     // put your main code here, to run repeatedly:
  65.     readTemperature(); // Read temperature and update LED state
  66.     updateOutputs(); // Refresh output data
  67. }
  68.  
  69. void readTemperature()
  70. {
  71.     // Read temperature as Celsius
  72.     tt_LED_PIN_D4_phyData = dht.readTemperature();
  73.  
  74.     // Check if the reading is valid
  75.     if (isnan(tt_LED_PIN_D4_phyData)) {
  76.         tt_LED_PIN_D4_rawData = false; // Turn off LED if reading fails
  77.     } else {
  78.         // Check if temperature reaches 60 degrees Celsius
  79.         if (tt_LED_PIN_D4_phyData >= 60.0) {
  80.             tt_LED_PIN_D4_rawData = true; // Turn on LED
  81.         } else {
  82.             tt_LED_PIN_D4_rawData = false; // Turn off LED
  83.         }
  84.     }
  85. }
  86.  
  87. void updateOutputs()
  88. {
  89.     digitalWrite(tt_LED_PIN_D4, tt_LED_PIN_D4_rawData);
  90. }
  91.  
  92. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement