Skip to content

Create a Battery Class #5

Description

@theDataSmith

Create a Battery Class that reads the voltage of the battery and can tell when the battery crosses below a given threshold (BATTERY_VOLTAGE_MIN). It should have a function that returns true if the battery voltage is below the threshold, false otherwise. Because the voltage read by the pin might not be accurate, we need to wait until we have multiple readings, and only return true if:

  • A minimum number of readings have been recorded.
  • Those readings are all similar to each other.
  • The average of those readings is below a given threshold.

Therefore, the class should store a number of readings in a queue (BATTERY_N_READINGS), and return false if the queue isn't full. It could then first calculate the average value of the readings, and return false if any one reading differs from the average by more than (BATTERY_MAX_DISCREPANCY).

Needed Arduino functions:
pinMode()
analogRead()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions