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
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.
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.
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.
display_temperature
Enables I2C communication, sends a start condition, writes the device address, and sends the data value for display.
update_i2c_value
Ensures data transmission over I2C, sends a stop condition, and then calls display_temperature to update the display value.
show_display
Retrieves the unit and tens values of the temperature and updates the respective I2C displays with the correct encoding for each digit.
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
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.
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.
obtain_unit_value
andobtain_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.
display_temperature
Enables I2C communication, sends a start condition, writes the device address, and sends the data value for display.
update_i2c_value
Ensures data transmission over I2C, sends a stop condition, and then calls
display_temperature
to update the display value.show_display
Retrieves the unit and tens values of the temperature and updates the respective I2C displays with the correct encoding for each digit.