Advertisement
pleasedontcode

**Data Display** rev_62

Oct 12th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Data Display**
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-12 22:04:21
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Read temperature from DS18B20 sensor and display */
  21.     /* on LCD screen. */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* Perform a countdown of 10 seconds after each */
  24.     /* temperature reading using LiquidCrystal library */
  25.     /* for display control. */
  26. /****** SYSTEM REQUIREMENT 3 *****/
  27.     /* use max pulse oximeter */
  28. /****** SYSTEM REQUIREMENT 4 *****/
  29.     /* use non blocking code. */
  30. /****** END SYSTEM REQUIREMENTS *****/
  31.  
  32. /* START CODE */
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <Wire.h>
  36. #include <DS18B20.h>    // DS18B20 library for temperature sensor
  37. #include <LiquidCrystal.h>    // LiquidCrystal library for LCD
  38. #include <MAX30100_PulseOximeter.h>    // MAX30100 library for pulse oximeter
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43. void readTemperature();
  44. void displayCountdown();
  45.  
  46. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  47. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2 = 2;
  48. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4 = 4;
  49.  
  50. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  51. const uint8_t myLCD_LCD1602_RS_PIN_D3 = 3;
  52. const uint8_t myLCD_LCD1602_D4_PIN_D5 = 5;
  53. const uint8_t myLCD_LCD1602_D5_PIN_D6 = 6;
  54. const uint8_t myLCD_LCD1602_D6_PIN_D7 = 7;
  55. const uint8_t myLCD_LCD1602_D7_PIN_D8 = 8;
  56.  
  57. /***** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  58. // DS18B20 instance
  59. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  60. // LiquidCrystal instance
  61. 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);
  62. // MAX30100 Pulse Oximeter instance
  63. PulseOximeter pox;
  64.  
  65. unsigned long lastReadTime = 0;
  66. const unsigned long readInterval = 10000; // Read every 10 seconds
  67. unsigned long countdownStartTime = 0;
  68. bool countdownActive = false;
  69.  
  70. void setup(void)
  71. {
  72.     Serial.begin(9600);
  73.     lcd.begin(16, 2); // Initialize the LCD
  74.     ds.selectNext(); // Initialize DS18B20 sensor
  75.  
  76.     // Set up pins
  77.     pinMode(PulseOximeter_MAX30100_INT_PIN_D2, INPUT_PULLUP);
  78.     pinMode(temperatureSensor_DS18B20_DQ_PIN_D4, INPUT);
  79.  
  80.     // Initialize the Pulse Oximeter
  81.     if (!pox.begin()) {
  82.         Serial.println("Failed to initialize pulse oximeter");
  83.         while (1);
  84.     }
  85.     pox.setOnBeatDetectedCallback([]() { Serial.println("Beat detected!"); });
  86. }
  87.  
  88. void loop(void)
  89. {
  90.     // Check if it's time to read the temperature
  91.     unsigned long currentMillis = millis();
  92.     if (currentMillis - lastReadTime >= readInterval) {
  93.         lastReadTime = currentMillis;
  94.         readTemperature(); // Read temperature and display
  95.     }
  96.  
  97.     if (countdownActive) {
  98.         unsigned long elapsed = millis() - countdownStartTime;
  99.         int remaining = 10 - (elapsed / 1000);
  100.         if (remaining >= 0) {
  101.             lcd.setCursor(0, 1); // Move to the second line
  102.             lcd.print("Countdown: ");
  103.             lcd.print(remaining);
  104.         } else {
  105.             countdownActive = false; // Stop countdown after 10 seconds
  106.             lcd.clear(); // Clear LCD after countdown
  107.         }
  108.     }
  109.  
  110.     pox.update(); // Update the pulse oximeter
  111. }
  112.  
  113. void readTemperature() {
  114.     float temperature = ds.getTempC(); // Get temperature from DS18B20
  115.     lcd.clear();
  116.     lcd.print("Temp: ");
  117.     lcd.print(temperature);
  118.     lcd.print(" C");
  119.     countdownStartTime = millis(); // Start countdown timer
  120.     countdownActive = true; // Activate countdown
  121. }
  122.  
  123. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement