Advertisement
pleasedontcode

"Data Display" rev_65

Oct 12th, 2024
54
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 23:03:36
  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.  
  33. /********* User code review feedback **********
  34. #### Feedback 1 ####
  35. - display also max pulse oximeter
  36. #### Feedback 2 ####
  37. - .ino file too long. put a library to clean the code.
  38. ********* User code review feedback **********/
  39.  
  40. /* START CODE */
  41.  
  42. /****** DEFINITION OF LIBRARIES *****/
  43. #include <Wire.h>
  44. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  45. #include <LiquidCrystal.h>  //https://github.com/arduino-libraries/LiquidCrystal
  46. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  47. #include <MAX30100_PulseOximeter.h> // This library is now created
  48.  
  49. /****** FUNCTION PROTOTYPES *****/
  50. void setup(void);
  51. void loop(void);
  52. void updateOutputs();
  53. void readTemperature();
  54. void displayCountdown(int seconds);
  55. void displayPulseOximeterData(); // New function prototype
  56.  
  57. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  58. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9       = 9;
  59. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2     = 2;
  60. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4       = 4;
  61.  
  62. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  63. const uint8_t myLCD_LCD1602_RS_PIN_D3       = 3;
  64. const uint8_t myLCD_LCD1602_D4_PIN_D5       = 5;
  65. const uint8_t myLCD_LCD1602_D5_PIN_D6       = 6;
  66. const uint8_t myLCD_LCD1602_D6_PIN_D7       = 7;
  67. const uint8_t myLCD_LCD1602_D7_PIN_D8       = 8;
  68.  
  69. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  70. float temperature = 0.0; // Variable to store temperature
  71. bool displayReady = true; // Flag to check if display is ready for next update
  72.  
  73. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  74. // DS18B20 sensor instance
  75. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  76. // LCD instance
  77. 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);
  78. // Pulse Oximeter instance
  79. PulseOximeter pox;
  80.  
  81. void setup(void)
  82. {
  83.     Serial.begin(9600);
  84.    
  85.     // Initialize LCD
  86.     lcd.begin(16, 2);
  87.     lcd.clear();
  88.    
  89.     // Initialize DS18B20
  90.     ds.begin();
  91.    
  92.     // Initialize Pulse Oximeter
  93.     if (!pox.begin()) {
  94.         Serial.println("Failed to initialize Pulse Oximeter");
  95.         while (1);
  96.     }
  97.    
  98.     // Set up Pulse Oximeter
  99.     pox.setOnBeatDetectedCallback([]() {
  100.         Serial.println("Beat detected!");
  101.     });
  102. }
  103.  
  104. void loop(void)
  105. {
  106.     pox.update(); // Update pulse oximeter readings
  107.  
  108.     if (displayReady) {
  109.         readTemperature(); // Read temperature from DS18B20
  110.         displayCountdown(10); // Display countdown
  111.         displayPulseOximeterData(); // Display pulse oximeter data
  112.     }
  113. }
  114.  
  115. void readTemperature() {
  116.     temperature = ds.getTempC();
  117.     lcd.clear();
  118.     lcd.print("Temp: ");
  119.     lcd.print(temperature);
  120.     lcd.print(" C");
  121.     displayReady = false; // Set flag to false until countdown is complete
  122. }
  123.  
  124. void displayCountdown(int seconds) {
  125.     for (int i = seconds; i > 0; i--) {
  126.         lcd.setCursor(0, 1); // Move cursor to the second line
  127.         lcd.print("Countdown: ");
  128.         lcd.print(i);
  129.         delay(1000); // Wait for 1 second
  130.     }
  131.     displayReady = true; // Set flag to true after countdown
  132. }
  133.  
  134. void displayPulseOximeterData() {
  135.     lcd.clear();
  136.     lcd.setCursor(0, 0); // Move cursor to the first line
  137.     lcd.print("HR: ");
  138.     lcd.print(pox.getHeartRate());
  139.     lcd.print(" bpm");
  140.    
  141.     lcd.setCursor(0, 1); // Move cursor to the second line
  142.     lcd.print("SpO2: ");
  143.     lcd.print(pox.getSpO2());
  144.     lcd.print(" %");
  145. }
  146.  
  147. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement