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 14:58:13
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* a thermostat with offset on and offset off logic. */
- /* Freertos is used. The thermostat recipe has the */
- /* name of the recipe, the step number, the step */
- /* temperature, and the step time in minutes. The set */
- /* temperature is maintained during each step. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- #include <OneWire.h> // Include OneWire library for DS18B20
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void thermostatTask(void *pvParameters); // FreeRTOS task for thermostat
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Temp_Sensor_DS18B20_DQ_PIN_D4 = 4;
- /***** THERMOSTAT RECIPE STRUCTURE *****/
- struct ThermostatStep {
- const char* recipeName;
- int stepNumber;
- float stepTemperature;
- int stepTime; // in minutes
- };
- /***** THERMOSTAT RECIPE EXAMPLE *****/
- ThermostatStep currentStep = {"Heating", 1, 25.0, 10}; // Example step
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- OneWire oneWire(Temp_Sensor_DS18B20_DQ_PIN_D4); // OneWire instance
- DS18B20 ds18b20(&oneWire); // DS18B20 instance
- /****** FREE RTOS TASK HANDLE *****/
- TaskHandle_t thermostatTaskHandle = NULL;
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(115200);
- // Initialize the DS18B20 sensor
- if (!ds18b20.begin()) {
- Serial.println("Could not find a valid DS18B20 sensor!");
- while (1);
- }
- // Create the thermostat task
- xTaskCreate(
- thermostatTask, // Task function
- "ThermostatTask", // Name of the task
- 2048, // Stack size (bytes)
- NULL, // Parameter passed to the task
- 1, // Task priority
- &thermostatTaskHandle // Task handle
- );
- }
- void loop(void)
- {
- // The loop can be used for other tasks if needed
- vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for a second
- }
- void thermostatTask(void *pvParameters)
- {
- // Run the thermostat logic
- while (true) {
- // Request temperature from the sensor
- ds18b20.requestTemperatures();
- float currentTemperature = ds18b20.getTempC();
- // Check if the current temperature is below the set temperature
- if (currentTemperature < currentStep.stepTemperature) {
- // Logic to turn on heating (not implemented)
- Serial.println("Heating ON");
- } else {
- // Logic to turn off heating (not implemented)
- Serial.println("Heating OFF");
- }
- // Wait for the duration of the step
- vTaskDelay(currentStep.stepTime * 60000 / portTICK_PERIOD_MS); // Convert minutes to milliseconds
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement