Skip to content

Commit 0887ca0

Browse files
authored
Update mkr-battery-app-note.md
Fix data type of variable max_Source_voltage. Float is correct here to get correct values. Made calculation of the two voltages better. No real change, but more accurate results this way.
1 parent d4a22cd commit 0887ca0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

content/hardware/01.mkr/01.boards/mkr-wifi-1010/tutorials/mkr-battery-app-note/mkr-battery-app-note.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ We will go through the lines needed to create a Sketch to read the battery value
124124
**4.** We will now create a variable to store the maximum source voltage `max_Source_voltage` as well as the upper (`batteryFullVoltage`) and lower (`batteryEmptyVoltage`) values for the battery. We will also define the battery capacity as `batteryCapacity` so as to determine the charging current. Since we are using a 750 mAh battery in this example, we will set the value to `0.750`.
125125

126126
```arduino
127-
int max_Source_voltage;
127+
float max_Source_voltage;
128128
129129
float batteryFullVoltage = 4.2;
130130
float batteryEmptyVoltage = 3.3;
@@ -303,8 +303,8 @@ void loop()
303303
{
304304
305305
rawADC = analogRead(ADC_BATTERY); //the value obtained directly at the PB09 input pin
306-
voltADC = rawADC * (3.3/4095.0); //convert ADC value to the voltage read at the pin
307-
voltBat = voltADC * (max_Source_voltage/3.3); //we cannot use map since it requires int inputs/outputs
306+
voltADC = rawADC * 3.3 / 4096.0; //convert ADC value to the voltage read at the pin
307+
voltBat = max_Source_voltage * rawADC / 4096.0; //we cannot use map since it requires int inputs/outputs
308308
309309
int new_batt = (voltBat - batteryEmptyVoltage) * (100) / (batteryFullVoltage - batteryEmptyVoltage); //custom float friendly map function
310310

0 commit comments

Comments
 (0)