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:32: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 readTemperature(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t DHT22_DOUT_PIN_D4 = 4;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t LED_PIN_D14 = 14;
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t Servomotor_PWMSignal_PIN_D13 = 13;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool LED_PIN_D14_rawData = 0;
- uint8_t Servomotor_PWMSignal_PIN_D13_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float LED_PIN_D14_phyData = 0.0;
- float Servomotor_PWMSignal_PIN_D13_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the DHT sensor
- DHT dht(DHT22_DOUT_PIN_D4, DHT22);
- // Create an instance of the Servo
- Servo servo;
- void setup(void)
- {
- // Initialize the DHT sensor
- dht.begin();
- // Set pin modes
- pinMode(LED_PIN_D14, OUTPUT);
- pinMode(Servomotor_PWMSignal_PIN_D13, OUTPUT);
- }
- void loop(void)
- {
- // Read temperature and update outputs
- readTemperature();
- updateOutputs(); // Refresh output data
- }
- void readTemperature()
- {
- // Read temperature from the DHT sensor
- float temperature = dht.readTemperature();
- // Check if the reading is valid
- if (isnan(temperature)) {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- // Check if temperature reaches 60 degrees
- if (temperature >= 60) {
- LED_PIN_D14_rawData = true; // Turn on LED
- } else {
- LED_PIN_D14_rawData = false; // Turn off LED
- }
- // You can add additional logic for the servo if needed
- }
- void updateOutputs()
- {
- digitalWrite(LED_PIN_D14, LED_PIN_D14_rawData);
- analogWrite(Servomotor_PWMSignal_PIN_D13, Servomotor_PWMSignal_PIN_D13_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement