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 Display
- - Source Code NOT compiled for: Arduino Nano ESP32
- - Source Code created on: 2024-10-02 23:10:54
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Initialize internal Bluetooth device as master, */
- /* receive BLE data, and show it on a 16x2 LCD using */
- /* LiquidCrystal library for Arduino. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* read temperature and send it via bluetooth. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <LiquidCrystal.h> // https://github.com/arduino-libraries/LiquidCrystal
- #include <DS18B20.h> // https://github.com/matmunk/DS18B20
- #include <Adafruit_SSD1306.h> // https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
- #include <U8g2_for_Adafruit_GFX.h> // https://github.com/olikraus/U8g2_for_Adafruit_GFX
- #include <DHT.h> // https://github.com/adafruit/DHT-sensor-library
- #include "BluetoothController.h" // Include the header for the LCD controller
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void sendTemperatureViaBluetooth(float temperature);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t temperatureSensor_DHT22_DOUT_PIN = 9; // DHT22 sensor pin
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create instances of the display and U8g2 objects
- Adafruit_SSD1306 display(OLED_RESET); // OLED display instance
- U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; // U8g2 instance
- LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // LCD instance
- DHT dht(temperatureSensor_DHT22_DOUT_PIN, DHT22); // DHT sensor instance
- void setup(void)
- {
- Serial.begin(9600); // Initialize serial communication
- pinMode(temperatureSensor_DHT22_DOUT_PIN, INPUT_PULLUP);
- initializeLCD(); // Initialize the LCD display
- setupDS18B20(); // Setup DS18B20 sensor
- dht.begin(); // Initialize the DHT sensor
- display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Initialize the OLED display
- display.display(); // Clear the display
- delay(2000);
- display.clearDisplay();
- }
- void loop(void)
- {
- updateOutputs(); // Refresh output data
- checkTemperature(); // Check temperature from DS18B20
- }
- void updateOutputs()
- {
- // Example of updating LCD display
- lcd.setCursor(0, 0);
- lcd.print("Temp: ");
- float temperature = dht.readTemperature(); // Read temperature from DHT sensor
- lcd.print(temperature);
- lcd.print(" C");
- // Send temperature via Bluetooth
- sendTemperatureViaBluetooth(temperature);
- }
- void sendTemperatureViaBluetooth(float temperature)
- {
- // Send the temperature data over Bluetooth
- Serial.print("Temperature: ");
- Serial.println(temperature);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement