millis "blink without delay" where did I mess it up

Hi Folks
I had the blink without delay code working to send results via Serial. I tried to tidy up the code layout and have messed something up.
It should send via serial every 10 seconds (10,000 millis) but it is constantly sending.

I am hoping someone can point to an error that I can understand and work to resolve.

The final program will be used to datalog a battery discharge test, I have tested all the individual components and have had them working with delays but now its time to remove the delays. I can then add in the Datalogger and RTC etc.

#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2); // set the LCD address to 0x3f for a 16 chars and 2 line display
int BattPin = A0;    // select the input pin for the potentiometer
int BattRawValue;  // variable to store the value coming from the pot
int BattVoltCalc; //Variable to store "mapped" result
int BattVolt; // Battery Voltage BattVoltCalc divided by 100
int BattVoltRem; // Battery Volt Calc remainder
//int VPCcalc; // Stores Volts per Cell (BattVolt/12)
int VPC;
int VPCdec;
int VPCrem;
unsigned long LCDcurrentMillis;
unsigned long LCDpreviousMillis = 0;        // will store last time LCD was updated
int LCDinterval = 500;           // interval at which to update LCD display(milliseconds)
unsigned long currentMillis;
unsigned long DLOGpreviousMillis = 0;        // will store last time Datalog was updated
long DLOGinterval = 10000L;           // interval at which to update Data Log (milliseconds)

void setup() {
  lcd.init(); // Start LCDlcd.init(); // Start LCD
  Serial.begin(9600); // Open serial communications and wait for port to open:
  while (!Serial) {
    // wait for serial port to connect. Needed for native USB port only


void loop() {

    BattRawValue = analogRead(BattPin);
    BattVoltCalc = map(BattRawValue, 0, 1023, 0, 3000);
    BattVolt = BattVoltCalc / 100;
    BattVoltRem = BattVoltCalc % 100;
    VPC = BattVoltCalc / 12;
    VPCdec = VPC / 100;
    VPCrem = VPC % 100;
   /* LCDcurrentMillis = millis();
    if (LCDcurrentMillis - LCDpreviousMillis >= LCDinterval)
      LCDpreviousMillis = LCDcurrentMillis;
    lcd.setCursor(0, 0);
    lcd.print ('.');
    lcd.print(" ");
    //lcd.print ('/');
    // lcd.print(now.year(), DEC);
    // lcd.print (' ');
    // lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
    //lcd.setCursor(4, 1);
    lcd.print(" VPC");
   lcd.print(now.second(), DEC);
    currentMillis = millis();
    if (currentMillis - DLOGpreviousMillis >= DLOGinterval)
      DLOGpreviousMillis = currentMillis;
    Serial.print("V ");

Thanks in advance

I think you're missing some of these {}

You haven't used brackets {} to enclose the code you want to execute on your if statement.

I thought that might be the case but it stopped working when I tried to break it into separate sections and added extra's of those.

I think I have all balanced pairs of {}?

Thanks for the pointer though I will go back and relook at that

thanks aarg Thats very useful

I always use braces, even when they're not necessary because it makes it easier to understand the intent of the code at a glance.

When your code isn't working correctly pay attention to the indentation of the code after you do an Auto Format. You can see that it was giving you a clue to the problem:

     if (currentMillis - DLOGpreviousMillis >= DLOGinterval)
      DLOGpreviousMillis = currentMillis;
    Serial.print("V ");

I think I have all balanced pairs of {}?

If you hadn't, the compiler would've bitched about it.

Thanks for the help everybody, it is now working I will now work on the LCD component.

If you hadn't, the compiler would've bitched about it.

True but I am still learning ( I have programmed in BASIC and used various forms of Ladder Logic in industrial controllers) and am trying to use the tools including the matched pair tool.

You mentioned “extra” brackets. Get rid of them.

You mentioned “extra” brackets. Get rid of them.

I have I think? I will setup the LDC next then test again.
This time I will remember to save as before making changes.