 
 void loop()
 {
+    getTime();
+
     if ( mode != MODE_SERIAL_MON)
     {
         mode %= NUM_MODE_ENUMS;


    if ( ButtonsChanged() )
    {
        lcd_timer = 0;
        light = true;
    }
    int mode_button = digitalRead(2);
    elapsedMillis = getTime();
    double vcc = ((double) readVcc() / 1000.0);
    dtostrf(vcc, 5, 3, str_vcc);

    if( charging || discharging )
    {
        current_mA = ina219.getCurrent_mA();
        if( discharging )
        {
            unsigned long currentTime = millis();
            long elapsedTime = currentTime - lastMeassureTime;
            if(elapsedTime < 0)
            {
                //TODO: handle overflow!
            }
            mAh += (current_mA * ((double)elapsedTime/1000.0)) / (60 * 60);
            dtostrf(mAh, 8, 0, str_mAh);
        }
    }
    else

LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//LiquidCrystal_I2C lcd(0x3f,16,2);

unsigned long g_lastSeconds = 0;
unsigned long g_lastMillis = 0;
unsigned long g_elapsedMillis = 0;
unsigned long g_elapsedSeconds = 0;
unsigned long g_totalSeconds = 0;
unsigned long g_seconds = 0;
unsigned long g_minutes = 0;
unsigned long g_hours = 0;
unsigned long g_lcd_timer = 0;
unsigned long g_lcd_timeout = 20;
unsigned long g_dischargeStart = 0;
unsigned long g_dischargeElapsed = 0;
unsigned long g_lastMeassureTime = 0;
double g_mAh = 0;
bool g_tick = false;

unsigned long getTime()
{
    unsigned long Millis = millis();
    if ( Millis < g_lastMillis ) // overflow!
    {
        g_lastMillis = 0;
    }
    unsigned long currentSeconds = ( Millis / 1000 );

    g_elapsedSeconds = ( currentSeconds - g_lastSeconds );

    g_elapsedMillis = Millis - g_lastMillis;
    g_lastMillis = Millis;
    if ( g_elapsedSeconds > 0 )
    {
        g_seconds += g_elapsedSeconds;
        g_totalSeconds += g_elapsedSeconds;
        g_lastSeconds = currentSeconds;
        g_lcd_timer += g_elapsedSeconds;
        g_tick = true;
    }
    if ( g_seconds >= 60 )
    {
        ++g_minutes;
        g_seconds = 0;
    }
    if ( g_minutes >= 60 )
    {
        ++g_hours;
        g_minutes = 0;
    }
    return g_elapsedMillis;
}

void GetButtonsStr( char* str )
