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-21 15:38:36
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The thermostat maintains a temperature of 21 */
- /* degrees for 100 seconds using RTOS */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- #include <OneWire.h> // Required for OneWire operations
- #include <freertos/FreeRTOS.h> // Include FreeRTOS library
- #include <freertos/task.h> // Include FreeRTOS task related functions
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void temperatureControlTask(void * parameter);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Temp_Sensor_DS18B20_DQ_PIN_D4 = 4;
- DS18B20 sensor(new OneWire(Temp_Sensor_DS18B20_DQ_PIN_D4)); // Create an instance of DS18B20 with OneWire
- /****** FUNCTION IMPLEMENTATIONS *****/
- void setup(void)
- {
- Serial.begin(115200);
- serial.println("Thermostat Starting");
- sensor.begin();
- // Create a FreeRTOS task for temperature control
- xTaskCreate(
- temperatureControlTask, // Function to implement the task
- "Temperature Control", // Name of the task
- 1024, // Stack size in words
- NULL, // Task input parameter
- 1, // Priority of the task
- NULL // Task handle
- );
- }
- void loop(void)
- {
- // Loop remains empty as tasks run in the background
- }
- // Temperature control task
- void temperatureControlTask(void * parameter)
- {
- const float targetTemperature = 21.0; // Target temperature
- const int duration = 100000; // Run time in milliseconds (100 seconds)
- uint32_t startTime = xTaskGetTickCount();
- while ((xTaskGetTickCount() - startTime) * portTICK_PERIOD_MS < duration)
- {
- sensor.requestTemperatures();
- float currentTemperature = sensor.getTempC(); // Request and retrieve current temperature
- Serial.print("Current Temperature: ");
- Serial.println(currentTemperature);
- // Additional code to maintain temperature can be added here
- vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1 second to prevent flooding the output
- }
- Serial.println("Temperature Control Finished");
- vTaskDelete(NULL); // Delete the task when done
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement