Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 Control**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-26 06:29:06
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* 温度到达 60led亮灯 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DHT.h> //https://github.com/adafruit/DHT-sensor-library
- #include <Deneyap_Servo.h> //https://github.com/deneyapkart/deneyap-servo-arduino-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void checkTemperature(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t DHT22_DOUT_PIN = 4; // Corrected variable name
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t Servomotor_PWMSignal_PIN = 13; // Corrected variable name
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- uint8_t Servomotor_PWMSignal_rawData = 0; // Corrected variable name
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float Servomotor_PWMSignal_phyData = 0.0; // Corrected variable name
- /****** DHT SENSOR INSTANCE *****/
- DHT dht(DHT22_DOUT_PIN, DHT22); // Create DHT sensor instance
- /****** DEFINITION OF LED PIN *****/
- const uint8_t LED_PIN = 2; // Define LED pin
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(DHT22_DOUT_PIN, INPUT_PULLUP);
- pinMode(Servomotor_PWMSignal_PIN, OUTPUT);
- pinMode(LED_PIN, OUTPUT); // Set LED pin as output
- dht.begin(); // Initialize DHT sensor
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- checkTemperature(); // Check temperature and control LED
- }
- void updateOutputs()
- {
- analogWrite(Servomotor_PWMSignal_PIN, Servomotor_PWMSignal_rawData);
- }
- void checkTemperature()
- {
- float temperature = dht.readTemperature(); // Read temperature from DHT sensor
- if (isnan(temperature)) {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- if (temperature >= 60) {
- digitalWrite(LED_PIN, HIGH); // Turn on LED if temperature is 60 or above
- } else {
- digitalWrite(LED_PIN, LOW); // Turn off LED otherwise
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement