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: **Data Display**
- - Source Code NOT compiled for: Arduino Nano ESP32
- - Source Code created on: 2024-10-10 17:13:17
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Read temperature from DS18B20 sensor and display */
- /* on LCD screen. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Perform a countdown of 10 seconds after each */
- /* temperature reading using LiquidCrystal library */
- /* for display control. */
- /****** SYSTEM REQUIREMENT 3 *****/
- /* use max pulse oximeter */
- /****** SYSTEM REQUIREMENT 4 *****/
- /* use non blocking code. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- #include <LiquidCrystal.h> //https://github.com/arduino-libraries/LiquidCrystal
- #include <MAX30100_PulseOximeter.h> //https://github.com/gabriel-milan/Arduino-MAX30100
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void readTemperature(); // Function to read temperature
- void displayTemperature(); // Function to display temperature
- void countdown(); // Countdown function
- void readPulseOximeter(); // Read from pulse oximeter
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t PulseOximeter_MAX30100_INT_PIN_D2 = 2;
- const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4 = 4;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t myLCD_LCD1602_RS_PIN_D3 = 3;
- const uint8_t myLCD_LCD1602_D4_PIN_D5 = 5;
- const uint8_t myLCD_LCD1602_D5_PIN_D6 = 6;
- const uint8_t myLCD_LCD1602_D6_PIN_D7 = 7;
- const uint8_t myLCD_LCD1602_D7_PIN_D8 = 8;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float temperature = 0.0; // Variable to store temperature
- unsigned long countdownStart = 0; // Start time for countdown
- bool countdownActive = false; // Is countdown active?
- int countdownValue = 10; // Countdown value
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create instances for the sensors
- DS18B20 ds18b20(temperatureSensor_DS18B20_DQ_PIN_D4);
- LiquidCrystal lcd(myLCD_LCD1602_RS_PIN_D3, myLCD_LCD1602_D4_PIN_D5, myLCD_LCD1602_D5_PIN_D6, myLCD_LCD1602_D6_PIN_D7, myLCD_LCD1602_D7_PIN_D8);
- PulseOximeter pulseOximeter;
- void setup(void)
- {
- Serial.begin(9600);
- lcd.begin(16, 2); // Initialize LCD
- ds18b20.resetSearch(); // Prepare DS18B20 for reading
- pulseOximeter.begin(); // Initialize pulse oximeter
- }
- void loop(void)
- {
- // Read temperature and display it
- readTemperature();
- displayTemperature();
- // Handle countdown if active
- if (countdownActive) {
- countdown();
- } else {
- // Start countdown after displaying temperature
- countdownActive = true;
- countdownStart = millis();
- }
- // Read pulse oximeter data
- readPulseOximeter();
- }
- void readTemperature() {
- temperature = ds18b20.getTempC(); // Read temperature
- }
- void displayTemperature() {
- lcd.clear();
- lcd.print("Temp: ");
- lcd.print(temperature);
- lcd.print(" C");
- }
- void countdown() {
- unsigned long currentMillis = millis();
- if (currentMillis - countdownStart >= 1000) { // Check if a second has passed
- countdownValue--;
- countdownStart = currentMillis; // Reset countdown start time
- }
- lcd.setCursor(0, 1); // Set cursor to second row
- lcd.print("Countdown: ");
- lcd.print(countdownValue); // Display countdown value
- if (countdownValue <= 0) {
- countdownActive = false; // Stop countdown
- countdownValue = 10; // Reset countdown value
- }
- }
- void readPulseOximeter() {
- pulseOximeter.update(); // Update pulse oximeter readings
- Serial.print("Heart rate: ");
- Serial.print(pulseOximeter.getHeartRate());
- Serial.print(" bpm / SpO2: ");
- Serial.println(pulseOximeter.getSpO2());
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement