diff --git a/platformio.ini b/platformio.ini index 8e58965..0a5447b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,6 +12,7 @@ platform = atmelavr board = pro8MHzatmega328 framework = arduino +monitor_speed = 115200 lib_deps = mysensors/MySensors@^2.3.2 thomasfredericks/Bounce2@^2.72 @@ -21,6 +22,7 @@ lib_deps = platform = atmelavr board = nanoatmega328new framework = arduino +monitor_speed = 115200 lib_deps = mysensors/MySensors@^2.3.2 thomasfredericks/Bounce2@^2.72 diff --git a/src/main.cpp b/src/main.cpp index f3125e4..d318d9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#define PRO_MINI // PRO_MINI o NANO +#define NANO // PRO_MINI o NANO #define MY_RADIO_RF24 #define MY_DEBUG @@ -54,7 +54,7 @@ MyMessage ch_comm_dht_temperature(DHT_ID_TEM, V_TEMP); MyMessage ch_comm_dht_humidity(DHT_ID_HUM, V_HUM); - const float VccMin = 3.7; + const float VccMin = 3.0; const float VccMax = 4.2; Vcc vcc; @@ -127,9 +127,10 @@ void loop() } int voltage = Vcc::measure(100, 1100); - int batteryPercent = static_cast(100.0 * (voltage - VccMin) / (VccMax - VccMin)); - if (batteryPercent > 100) batteryPercent = 100; - if (batteryPercent < 0) batteryPercent = 0; + int voltageV = voltage / 1000.0; + + int batteryPercent = static_cast(100.0 * (voltageV - VccMin) / (VccMax - VccMin)); + batteryPercent = constrain(batteryPercent, 0, 100); sendBatteryLevel(batteryPercent); // función de MySensor que envía el procentaje