D:/DRISSI/arduino-0022/arduino-0022/libraries/batteryCheck/batteryCheck.cpp
Go to the documentation of this file.
00001 
00007 /* Reads the voltage divider to calculate a battery voltage */
00008 
00009 #include "batteryCheck.h"
00010 
00011 
00012 int BatMon1Pin = 2;                                                     // Input pin for the divider
00013 int BatMon2Pin = 3;
00014 int Bat1val = 0;                                                        // Variable for the A/D value
00015 int Bat2val = 0; 
00016 float Pin2Voltage = 0;                                          // Variable to hold the calculated voltage
00017 float Pin3Voltage = 0;
00018 double Battery1Voltage = 0;
00019 double Battery2Voltage = 0;
00020 float Ratio = 5;                                                // Change this to match the MEASURED ration of the circuit
00021 
00022 
00023 // Get the state (voltage) of the first battery
00024 double Battery1State() 
00025 {  
00026 #ifdef __DEBUG__BC__
00027         Serial.println("Getting battery 1 voltage...");
00028 #endif
00029 
00030         Bat1val = analogRead(BatMon1Pin);               // Read the voltage on the divider  
00031  
00032         Pin2Voltage = Bat1val * 0.0048828125;           //  Calculate the voltage on the A/D pin
00033                                                                                         //  A reading of 1 for the A/D = 0.0048mV
00034                                                                                         //  If we multiply the A/D reading by 0.00488 then 
00035                                                                                         //  We get the voltage on the pin.                                  
00036                                     
00037                                     
00038   
00039         Battery1Voltage = Pin2Voltage * Ratio;  //  Use the ratio calculated for the voltage divider
00040                                                                                         //  To calculate the battery voltage
00041         return (Battery1Voltage); 
00042 }    
00043 
00044 
00045 // Get the state (voltage) of the second battery
00046 double Battery2State() 
00047 {         
00048 #ifdef __DEBUG__BC__
00049         Serial.println("Getting battery 2 voltage...");
00050 #endif
00051 
00052         Bat2val = analogRead(BatMon2Pin);               // Read the voltage on the divider  
00053   
00054         Pin3Voltage = Bat2val * 0.0048828125;           //  Calculate the voltage on the A/D pin
00055                                                                                         //  A reading of 1 for the A/D = 0.0048mV
00056                                                                                         //  If we multiply the A/D reading by 0.00488 then 
00057                                                                                         //  We get the voltage on the pin.                                  
00058                                     
00059 
00060         Battery2Voltage = Pin3Voltage * Ratio; 
00061 
00062         return (Battery2Voltage);                               //  To calculate the battery voltage                                       
00063 }