From 58ffb0fbc6fcd0107d49c18879a47496143b8b39 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 4 Jan 2017 09:37:07 +0100 Subject: [PATCH] Working w/ battery --- sodaq_one/nico.ino | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sodaq_one/nico.ino b/sodaq_one/nico.ino index 6fe84cf..4ee97fd 100644 --- a/sodaq_one/nico.ino +++ b/sodaq_one/nico.ino @@ -1,8 +1,11 @@ #include - +#define ADC_AREF 3.3f +#define BATVOLT_R1 2.0f +#define BATVOLT_R2 2.0f +#define BATVOLT_PIN BAT_VOLT int getB() { - return (float)analogRead(BAT_VOLT); + return ((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN)); }