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: Aa
- - Source Code compiled for: Arduino Nano
- - Source Code created on: 2023-12-04 14:25:51
- - Source Code generated by: Neeraj
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Lcd show current temperature and set temperature */
- /* set button to select set temperature for desired */
- /* temperature by up down button and led work on set */
- /* temperature and off Inc temperature */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Lcd show current temperature */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Wire.h>
- #include <DS18B20.h>
- #include <LiquidCrystal_I2C.h>
- /**
- * FUNCTION PROTOTYPES
- */
- void setup(void);
- void loop(void);
- void setTemperatureButtonInterrupt(void);
- float setTemperatureButtonLogic(float currentTemp);
- void displayTemperature(float currentTemp, float targetTemp);
- /**
- * DEFINITION OF DIGITAL INPUT PINS
- */
- const uint8_t Temp_DS18B20_DQ_PIN_D2 = 2;
- const uint8_t Set_Temperature_Button_PIN = 3;
- /**
- * DEFINITION OF I2C PINS
- */
- const uint8_t Lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
- const uint8_t Lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
- const uint8_t Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x39;
- /**
- * GLOBAL VARIABLES
- */
- float currentTemperature = 0;
- float setTemperature = 25;
- bool isSetMode = false;
- /**
- * DEFINITION OF LIBRARIES CLASS INSTANCES
- */
- DS18B20 tempSensor(Temp_DS18B20_DQ_PIN_D2);
- LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
- void setup(void)
- {
- // Initialize digital input pins
- pinMode(Temp_DS18B20_DQ_PIN_D2, INPUT);
- pinMode(Set_Temperature_Button_PIN, INPUT_PULLUP);
- // Begin LCD communication and display initial message
- lcd.begin(16, 2);
- lcd.backlight();
- lcd.print("DS18B20 Test");
- // Attach interrupt to the set temperature button pin
- attachInterrupt(digitalPinToInterrupt(Set_Temperature_Button_PIN), setTemperatureButtonInterrupt, FALLING);
- }
- void setTemperatureButtonInterrupt(void)
- {
- // Toggle the set temperature mode
- isSetMode = !isSetMode;
- if (isSetMode)
- {
- lcd.setCursor(0, 1);
- lcd.print("SET MODE "); // Update LCD to show set mode
- }
- else
- {
- lcd.clear(); // Clear the LCD
- }
- }
- void loop(void)
- {
- if (isSetMode)
- {
- setTemperature = setTemperatureButtonLogic(setTemperature); // Handle set temperature button logic when in set mode
- }
- displayTemperature(currentTemperature, setTemperature); // Wait for temperature updates
- delay(1000);
- }
- float setTemperatureButtonLogic(float currentTemp)
- {
- // Increment or decrement the set temperature based on the affected button press
- if (digitalRead(Set_Temperature_Button_PIN) == HIGH)
- {
- setTemperature++;
- if (setTemperature >= 50) // Restrict the maximum set temperature to 50
- {
- setTemperature = 50;
- }
- }
- else
- {
- setTemperature--;
- if (setTemperature <= 0) // Restrict the minimum set temperature to 0
- {
- setTemperature = 0;
- }
- }
- return setTemperature;
- }
- void displayTemperature(float currentTemp, float targetTemp)
- {
- lcd.setCursor(0, 0);
- lcd.print("Current: ");
- lcd.print(currentTemp);
- lcd.write(223); // Display degree symbol
- lcd.print("C");
- lcd.setCursor(0, 1);
- lcd.print("Target : ");
- lcd.print(targetTemp);
- lcd.write(223); // Display degree symbol
- lcd.print("C");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement