d

Dependencies:   mbed

main.cpp

Committer:
naray23
Date:
2017-08-21
Revision:
0:d6e64dfdbf63

File content as of revision 0:d6e64dfdbf63:

#include "mbed.h"


#define CUTOFF_MAX_VLTG  20000  //approx 1V
#define CUTOFF_MIN_VLTG  15000  //approx 0.5V

DigitalOut myled(LED_GREEN);
DigitalOut SwitchControl(PTD4,0);
Serial pc(USBTX, USBRX);
AnalogIn   ain(A0);

int main()
{
   unsigned int batteryvltg=0;
   SwitchControl=0;
   pc.printf("Started Charging\n\r");
   pc.baud(9600);
    while (true) 
    {
        SwitchControl =1;
        while(batteryvltg < 12000)
        {
            batteryvltg = ain.read_u16();
            //printf("%u \n\r", batteryvltg);
            wait(0.01);
        }
        while(batteryvltg < 20000)
        {
            batteryvltg = ain.read_u16();
            printf("%u \n\r", batteryvltg);
            wait(0.01);
        }
        //pc.printf("Cutoff point Reached\n\r");
        SwitchControl =0;
        batteryvltg = ain.read_u16();
        while(batteryvltg > 18500)
        {
            printf("%u \n\r", batteryvltg);
            batteryvltg = ain.read_u16();
            wait(0.0001);
      
        }
        while(batteryvltg > 15000)
        {
            printf("%u \n\r", batteryvltg);
            batteryvltg = ain.read_u16();
            wait(0.0001);
      
        }
    }
}