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-12 23:03:36
- ********* 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 *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - display also max pulse oximeter
- #### Feedback 2 ####
- - .ino file too long. put a library to clean the code.
- ********* User code review feedback **********/
- /* 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 <DHT.h> //https://github.com/adafruit/DHT-sensor-library
- #include <MAX30100_PulseOximeter.h> // This library is now created
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void readTemperature();
- void displayCountdown(int seconds);
- void displayPulseOximeterData(); // New function prototype
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
- 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 RAW VARIABLES *****/
- float temperature = 0.0; // Variable to store temperature
- bool displayReady = true; // Flag to check if display is ready for next update
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // DS18B20 sensor instance
- DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
- // LCD instance
- 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);
- // Pulse Oximeter instance
- PulseOximeter pox;
- void setup(void)
- {
- Serial.begin(9600);
- // Initialize LCD
- lcd.begin(16, 2);
- lcd.clear();
- // Initialize DS18B20
- ds.begin();
- // Initialize Pulse Oximeter
- if (!pox.begin()) {
- Serial.println("Failed to initialize Pulse Oximeter");
- while (1);
- }
- // Set up Pulse Oximeter
- pox.setOnBeatDetectedCallback([]() {
- Serial.println("Beat detected!");
- });
- }
- void loop(void)
- {
- pox.update(); // Update pulse oximeter readings
- if (displayReady) {
- readTemperature(); // Read temperature from DS18B20
- displayCountdown(10); // Display countdown
- displayPulseOximeterData(); // Display pulse oximeter data
- }
- }
- void readTemperature() {
- temperature = ds.getTempC();
- lcd.clear();
- lcd.print("Temp: ");
- lcd.print(temperature);
- lcd.print(" C");
- displayReady = false; // Set flag to false until countdown is complete
- }
- void displayCountdown(int seconds) {
- for (int i = seconds; i > 0; i--) {
- lcd.setCursor(0, 1); // Move cursor to the second line
- lcd.print("Countdown: ");
- lcd.print(i);
- delay(1000); // Wait for 1 second
- }
- displayReady = true; // Set flag to true after countdown
- }
- void displayPulseOximeterData() {
- lcd.clear();
- lcd.setCursor(0, 0); // Move cursor to the first line
- lcd.print("HR: ");
- lcd.print(pox.getHeartRate());
- lcd.print(" bpm");
- lcd.setCursor(0, 1); // Move cursor to the second line
- lcd.print("SpO2: ");
- lcd.print(pox.getSpO2());
- lcd.print(" %");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement