Advertisement
pleasedontcode

Temperature Control rev_11

Jan 26th, 2025
34
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:39:59
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* 温度到达 60led亮灯 */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24.  
  25. /* START CODE */
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs();
  34. void readTemperature(); // Function to read temperature
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t ttt_DHT22_DOUT_PIN_D13        = 13;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t tt_LED_PIN_D4     = 4;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. /***** used to store raw data *****/
  44. bool    tt_LED_PIN_D4_rawData       = 0;
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float   tt_LED_PIN_D4_phyData       = 0.0;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. // Create an instance of the DHT sensor
  52. DHT dht(ttt_DHT22_DOUT_PIN_D13, DHT22); // Assuming DHT22 sensor
  53.  
  54. void setup(void)
  55. {
  56.     // put your setup code here, to run once:
  57.     pinMode(ttt_DHT22_DOUT_PIN_D13, INPUT_PULLUP);
  58.     pinMode(tt_LED_PIN_D4, OUTPUT);
  59.    
  60.     dht.begin(); // Initialize the DHT sensor
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // put your main code here, to run repeatedly:
  66.     readTemperature(); // Read temperature and update LED state
  67.     updateOutputs(); // Refresh output data
  68. }
  69.  
  70. void readTemperature()
  71. {
  72.     // Read temperature as Celsius
  73.     tt_LED_PIN_D4_phyData = dht.readTemperature();
  74.  
  75.     // Check if the reading is valid
  76.     if (isnan(tt_LED_PIN_D4_phyData)) {
  77.         tt_LED_PIN_D4_rawData = false; // Turn off LED if reading fails
  78.     } else {
  79.         // Check if temperature reaches 60 degrees Celsius
  80.         if (tt_LED_PIN_D4_phyData >= 60.0) {
  81.             tt_LED_PIN_D4_rawData = true; // Turn on LED
  82.         } else {
  83.             tt_LED_PIN_D4_rawData = false; // Turn off LED
  84.         }
  85.     }
  86. }
  87.  
  88. void updateOutputs()
  89. {
  90.     digitalWrite(tt_LED_PIN_D4, tt_LED_PIN_D4_rawData);
  91. }
  92.  
  93. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement