ICOMP-UNC / Bit-Masters

MIT License
0 stars 0 forks source link

Alarm and notification #22

Closed daviddaguero closed 2 weeks ago

daviddaguero commented 2 weeks ago

Summary

This pull request introduces functions for reading the battery level, obtaining temperature values, and converting them to be displayed via I2C on external displays. These functions enable the system to read and display temperature values accurately within a range of 0–99, with error handling for values out of range. Additionally, a function for displaying battery level readings is added, utilizing the ADC.

Functions Added

  1. get_battery_value
    Reads the battery level using ADC, converts the result, and returns the battery level value. This function configures the ADC, initiates the conversion, waits until completion, and scales the result.

  2. convert_to_display
    Converts a numerical digit (0–9) into its corresponding 7-segment display encoding. This encoding is used for external displays to show numbers properly.

  3. obtain_unit_value and obtain_tens_value
    Reads the temperature and extracts the unit and tens digits, converting them into 7-segment display format. Both functions include error handling for temperature values above 99, displaying "r" or "E" respectively if the temperature exceeds this limit.

  4. display_temperature
    Enables I2C communication, sends a start condition, writes the device address, and sends the data value for display.

  5. update_i2c_value
    Ensures data transmission over I2C, sends a stop condition, and then calls display_temperature to update the display value.

  6. show_display
    Retrieves the unit and tens values of the temperature and updates the respective I2C displays with the correct encoding for each digit.