// -------------------------------------------------------------------------------------------------------------
// This code increments a variable (y) from 1 to 8. This could be used for cells 1 to 8.
// -------------------------------------------------------------------------------------------------------------
// The voltage divider will reduce the input voltage from a high of 3.65 to 3.3v
// The range of voltages therefore are between 0 and 3.3v
// The measured voltage is a derivative of 4095. To get the correct voltage value
// multiply the number by 3.3/4095 = .0008058608. For example, a value of 2048
// would mean the voltage is 2048 x .0008058608 = 1.6504029184v
// The battery charge is represented by percentages in the following chart:
// 2.25 = 0%
// 2.3535 = 10%
// 2.457 = 20%
// 2.5605 = 30%
// 2.664 = 40%
// 2.7675 = 50%
// 2.871 = 60%
// 2.9745 = 70%
// 3.078 = 80%
// 3.1815 = 90%
// 3.285 = 100%
// Pinv1 = voltage measured from Cell1
// Pinv2 = voltage measured from Cell2
// Pinv3 = voltage measured from Cell3
// Pinv4 = voltage measured from Cell4
// Pinv5 = voltage measured from Cell5
// Pinv6 = voltage measured from Cell6
// Pinv7 = voltage measured from Cell7
// Pinv8 = voltage measured from Cell8
// This voltage would need to be multiplied by 1.106060606 to get the true voltage of the cell
// Pinv1 = voltage measured from Cell1 x 1.106060606
// Pinv2 = voltage measured from Cell2 x 1.106060606
// Pinv3 = voltage measured from Cell3 x 1.106060606
// Pinv4 = voltage measured from Cell4 x 1.106060606
// Pinv5 = voltage measured from Cell5 x 1.106060606
// Pinv6 = voltage measured from Cell6 x 1.106060606
// Pinv7 = voltage measured from Cell7 x 1.106060606
// Pinv8 = voltage measured from Cell8 x 1.106060606
// But since we are looking for percentages this final calculation is not required
// ------- //
// Globals //
// ------- //
int x = 0;
int y = 0;
String BattCell = "Cell";
// BattCellGPIO() is the pin the battery cell is connected to
int BattCellGPIOPin[] {
32, 33, 34, 35, 36, 37, 38, 39
};
//
// Pinv() will store the GPIO value
int Pinv[] {
1, 2, 3, 4, 5, 6, 7, 8
};
//
void setup() {
Serial.begin(9600); // send and receive at 9600 baud
}
void loop() {
y = ++x;
Serial.print(BattCell);
Serial.println(y);
Serial.print("BattCellGPIOPin is : ");
Serial.println(BattCellGPIOPin[y-1]);
// Reading potentiometer value
Pinv[y] = analogRead(BattCellGPIOPin[y]);
Serial.print("Analog value: ");
Serial.println(Pinv[y]);
// Wait a bit before scanning again
delay(5000);
if (y == 8){
x = 0;
y = 0;
}
}
// ----------------
// End of code
// ----------------