Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "C_BatteryHandlerMEGA.h"
- using namespace std;
- class C_BatteryHandlerMEGA{
- C_BatteryHandlerMEGA::C_BatteryHandlerMEGA(int pin, int time_refresh = 1){
- this->pin = pin;
- this->time_refresh = time_refresh
- this->handleBattery();
- }
- void C_BatteryHandlerMEGA::handleBattery(){
- digitalWrite(BATTERY_HANDLER_PIN, battery_state);
- }
- bool C_BatteryHandlerMEGA::initMeasuring(){
- float time = (100*pow(10, -9))*(this->cpt++);
- if(time == this->time_refresh)){
- this->takeMeasure();
- this->handleBattery();
- }
- }
- void C_BatteryHandlerMEGA::takeMeasure(){
- int valeur = analogRead(this->pin);
- this->tension = valeur * (5/1023.0);
- this->checkTensionThreshold();
- }
- void C_BatteryHandlerMEGA::checkTensionThreshold(){
- if(this->tension <= MIN_TENSION){
- this->switch_battery = true;
- this->battery_state = 1;
- }
- }
- int C_BatteryHandlerMEGA::getBatteryPercent() const {
- return (int)(((this->tension-MIN_TENSION)/(MAX_TENSION-MIN_TENSION))*100);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement