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: "Thermostat Control"
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-21 14:47:37
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* a thermostat with an offset on and offset off */
- /* logic using Freertos. The thermostat works */
- /* according to the recipe, which is stored in the */
- /* EEprom memory. The recipe has the name, the step */
- /* number, the step temperature, and the step time in */
- /* minutes. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> // https://github.com/matmunk/DS18B20
- #include <OneWire.h>
- #include <EEPROM.h>
- #include <FreeRTOS.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void thermostatTask(void *pvParameters);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Temp_Sensor_DS18B20_DQ_PIN_D4 = 4;
- /***** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- #define ONE_WIRE_BUS 2
- OneWire oneWire(ONE_WIRE_BUS);
- DS18B20 sensor(&oneWire);
- // Recipe structure
- struct RecipeStep {
- String name;
- float temperature;
- int time; // in minutes
- };
- // Example recipe
- RecipeStep recipe[] = {
- {"Step 1", 25.0, 10},
- {"Step 2", 30.0, 15},
- {"Step 3", 35.0, 20}
- };
- // Current step index
- int currentStep = 0;
- // Offset values
- float offsetOn = 0.5;
- float offsetOff = 0.5;
- void setup(void)
- {
- Serial.begin(115200);
- pinMode(Temp_Sensor_DS18B20_DQ_PIN_D4, INPUT);
- sensor.begin();
- // Create FreeRTOS task for thermostat
- xTaskCreate(thermostatTask, "ThermostatTask", 2048, NULL, 1, NULL);
- }
- void loop(void)
- {
- // Main loop can remain empty as the thermostat logic is handled in the FreeRTOS task
- }
- void thermostatTask(void *pvParameters)
- {
- while (true) {
- sensor.requestTemperatures();
- float currentTemp = sensor.getTempC();
- // Check if we need to turn on or off the thermostat
- if (currentStep < sizeof(recipe) / sizeof(recipe[0])) {
- if (currentTemp < (recipe[currentStep].temperature - offsetOn)) {
- // Turn on heating
- Serial.println("Heating ON");
- } else if (currentTemp > (recipe[currentStep].temperature + offsetOff)) {
- // Turn off heating
- Serial.println("Heating OFF");
- currentStep++; // Move to the next step
- }
- } else {
- Serial.println("Recipe completed.");
- vTaskDelete(NULL); // Delete the task if the recipe is completed
- }
- // Delay for a while before the next temperature check
- vTaskDelay(pdMS_TO_TICKS(1000));
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement