Used for testing battery sense circuit, looking for max and min levels. Allow for finding true empty, half and full values for driving LEDs for example

Dependencies:   mbed MPL3115A2 TSI WiGo_BattCharger

main.cpp

Committer:
monpjc
Date:
2013-05-17
Revision:
1:b1921e153d21
Parent:
0:17ad5a30ff25
Child:
2:c08efa9effc8

File content as of revision 1:b1921e153d21:

#include "mbed.h"
#include "WiGo_BattCharger.h"

#define RGB_LED_ON  0
#define RGB_LED_OFF 1

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);

Serial pc(USBTX, USBRX);

WiGo_BattCharger Batt( BATT_LOW, BATT_MED, BATT_FULL, CHRG_EN1, CHRG_EN2, CHRG_SNS_EN, CHRG_SNS, CHRG_POK, CHRG_CHG);

float max_batt;
float batt_lvl;

int main()
{
    Batt.init();
    Batt.sense_en(1);

    wait(0.5);
    max_batt = Batt.read();


    while(1) {

        //If charging then blink Blue led to show we are alive
        if( Batt.charging() == CHARGING ) {
            myled2 = RGB_LED_OFF;
            myled3 = RGB_LED_OFF;

            myled1 = RGB_LED_ON;
            wait(0.1);
            myled1 = RGB_LED_OFF;
            wait(0.9);
        }

        //If no power applied (via USB) then turn all on, blink Bled led off
        if( Batt.supply() != POWER_OK ) {
            myled2 = RGB_LED_ON;
            myled3 = RGB_LED_ON;

            myled1 = RGB_LED_OFF;
            wait(0.1);
            myled1 = RGB_LED_ON;
            wait(0.9);
        }

        Batt.LEDupdate();

        batt_lvl = Batt.read();
        if( batt_lvl > max_batt ) {
            max_batt = batt_lvl;
        }

        pc.printf(">%f Max:%f\n\r", batt_lvl, max_batt);
    }
}