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

**URL:** <https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822>\
**Category:** Programming\
**Created:** [July 13, 2017, 8:50am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822 "2017-07-13T08:50:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiwi\_Bloke](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Kiwi\_Bloke](https://forum.arduino.cc/u/Kiwi_Bloke)\
**Post date:** [July 13, 2017, 8:50am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/1 "2017-07-13T08:50:00Z")

</div>

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.

```cpp
#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.backlight();
    lcd.setCursor(0, 0);
    lcd.print(BattVolt);
    lcd.print ('.');
    lcd.print(BattVoltRem);
    lcd.print("V");
    lcd.print(" ");
    //lcd.print ('/');
    // lcd.print(now.year(), DEC);
    // lcd.print (' ');
    // lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
    //lcd.setCursor(4, 1);
    lcd.print(VPCdec);
    lcd.print('.');
    lcd.print(VPCrem);
    lcd.print(" VPC");
  lcd.print(now.second(), DEC);
  */
  
 
    currentMillis = millis();
    if (currentMillis - DLOGpreviousMillis >= DLOGinterval)
      DLOGpreviousMillis = currentMillis;
    Serial.print(BattVolt);
    Serial.print(".");
    Serial.print(BattVoltRem);
    Serial.print("V ");
    Serial.print(VPCdec);
    Serial.print(".");
    Serial.print(VPCrem);
    Serial.println("VPC");
   
 
}

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 13, 2017, 8:50am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/2 "2017-07-13T08:50:57Z")

</div>

I think you're missing some of these {}

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [July 13, 2017, 8:52am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/3 "2017-07-13T08:52:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kiwi\_Bloke](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Kiwi\_Bloke](https://forum.arduino.cc/u/Kiwi_Bloke)\
**Post date:** [July 13, 2017, 8:54am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/4 "2017-07-13T08:54:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [July 13, 2017, 9:00am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/5 "2017-07-13T09:00:19Z")

</div>

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:

```cpp
     if (currentMillis - DLOGpreviousMillis >= DLOGinterval)
      DLOGpreviousMillis = currentMillis;
    Serial.print(BattVolt);
    Serial.print(".");
    Serial.print(BattVoltRem);
    Serial.print("V ");
    Serial.print(VPCdec);
    Serial.print(".");
    Serial.print(VPCrem);
    Serial.println("VPC");

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 13, 2017, 9:03am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/6 "2017-07-13T09:03:23Z")

</div>

> I think I have all balanced pairs of {}?

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

---

<div class="post-metadata">

**Author:** ![Kiwi\_Bloke](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Kiwi\_Bloke](https://forum.arduino.cc/u/Kiwi_Bloke)\
**Post date:** [July 13, 2017, 9:04am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/7 "2017-07-13T09:04:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kiwi\_Bloke](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Kiwi\_Bloke](https://forum.arduino.cc/u/Kiwi_Bloke)\
**Post date:** [July 13, 2017, 9:06am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/8 "2017-07-13T09:06:33Z")

</div>

> AWOL:  
> 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.

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [July 13, 2017, 9:07am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/9 "2017-07-13T09:07:16Z")

</div>

You mentioned "extra" brackets. Get rid of them.

---

<div class="post-metadata">

**Author:** ![Kiwi\_Bloke](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Kiwi\_Bloke](https://forum.arduino.cc/u/Kiwi_Bloke)\
**Post date:** [July 13, 2017, 9:09am UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/10 "2017-07-13T09:09:41Z")

</div>

> aarg:  
> 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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 10:37pm UTC](https://forum.arduino.cc/t/millis-blink-without-delay-where-did-i-mess-it-up/469822/11 "2021-05-05T22:37:53Z")

</div>

Closed on May 5, 2021, 10:37pm UTC


