Advertisement
pleasedontcode

**Data Display** rev_61

Oct 10th, 2024
70
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-10 17:13:17
  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>    //https://github.com/matmunk/DS18B20
  37. #include <LiquidCrystal.h>  //https://github.com/arduino-libraries/LiquidCrystal
  38. #include <MAX30100_PulseOximeter.h> //https://github.com/gabriel-milan/Arduino-MAX30100
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43. void readTemperature(); // Function to read temperature
  44. void displayTemperature(); // Function to display temperature
  45. void countdown(); // Countdown function
  46. void readPulseOximeter(); // Read from pulse oximeter
  47.  
  48. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  49. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2 = 2;
  50. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4 = 4;
  51.  
  52. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  53. const uint8_t myLCD_LCD1602_RS_PIN_D3 = 3;
  54. const uint8_t myLCD_LCD1602_D4_PIN_D5 = 5;
  55. const uint8_t myLCD_LCD1602_D5_PIN_D6 = 6;
  56. const uint8_t myLCD_LCD1602_D6_PIN_D7 = 7;
  57. const uint8_t myLCD_LCD1602_D7_PIN_D8 = 8;
  58.  
  59. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  60. float temperature = 0.0; // Variable to store temperature
  61. unsigned long countdownStart = 0; // Start time for countdown
  62. bool countdownActive = false; // Is countdown active?
  63. int countdownValue = 10; // Countdown value
  64.  
  65. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  66. // Create instances for the sensors
  67. DS18B20 ds18b20(temperatureSensor_DS18B20_DQ_PIN_D4);
  68. 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);
  69. PulseOximeter pulseOximeter;
  70.  
  71. void setup(void)
  72. {
  73.     Serial.begin(9600);
  74.     lcd.begin(16, 2); // Initialize LCD
  75.     ds18b20.resetSearch(); // Prepare DS18B20 for reading
  76.     pulseOximeter.begin(); // Initialize pulse oximeter
  77. }
  78.  
  79. void loop(void)
  80. {
  81.     // Read temperature and display it
  82.     readTemperature();
  83.     displayTemperature();
  84.  
  85.     // Handle countdown if active
  86.     if (countdownActive) {
  87.         countdown();
  88.     } else {
  89.         // Start countdown after displaying temperature
  90.         countdownActive = true;
  91.         countdownStart = millis();
  92.     }
  93.  
  94.     // Read pulse oximeter data
  95.     readPulseOximeter();
  96. }
  97.  
  98. void readTemperature() {
  99.     temperature = ds18b20.getTempC(); // Read temperature
  100. }
  101.  
  102. void displayTemperature() {
  103.     lcd.clear();
  104.     lcd.print("Temp: ");
  105.     lcd.print(temperature);
  106.     lcd.print(" C");
  107. }
  108.  
  109. void countdown() {
  110.     unsigned long currentMillis = millis();
  111.     if (currentMillis - countdownStart >= 1000) { // Check if a second has passed
  112.         countdownValue--;
  113.         countdownStart = currentMillis; // Reset countdown start time
  114.     }
  115.     lcd.setCursor(0, 1); // Set cursor to second row
  116.     lcd.print("Countdown: ");
  117.     lcd.print(countdownValue); // Display countdown value
  118.     if (countdownValue <= 0) {
  119.         countdownActive = false; // Stop countdown
  120.         countdownValue = 10; // Reset countdown value
  121.     }
  122. }
  123.  
  124. void readPulseOximeter() {
  125.     pulseOximeter.update(); // Update pulse oximeter readings
  126.     Serial.print("Heart rate: ");
  127.     Serial.print(pulseOximeter.getHeartRate());
  128.     Serial.print(" bpm / SpO2: ");
  129.     Serial.println(pulseOximeter.getSpO2());
  130. }
  131.  
  132. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement