Why this delay??

I cannot figure why,but when I print a "number" it stops printing when the seconds change instead of being always printing continuosly...It's not inside de "1 second" refresh, so I think this is very strange.. Can anyone help me?

void loop() {

  
  Serial.println(number);

  currentMillis = millis();

  if (currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;
     
    Serial.println();
    utc = now() + 3600; //- 3600L
    printTime(utc, "UTC");  //Prints UTC Time
    local = myTZ.toLocal(utc, &tcr);//
    printTime(local, tcr -> abbrev); //Prints Local Time

    sensorVal2 = analogRead(A2);

    voltage = sensorVal2 * 5.0;
    voltage /= 1024.0;

    if (avgFlag == true) {

      totVal += sensorVal2;
      avg = (totVal / x);
      x++;
      timer++;
    }

    xPos++;
  }



....and so on!

We need to see the rest of the code.

I don't get it, even if I "hide" the rest of the code inside the loop, it continues to have a delay... The code is still a "bit" messy:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <Time.h>
#include <Timezone.h>    //https://github.com/JChristensen/Timezone
#include <DS1307RTC.h>


//COLOR DEFINITIONS
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFE0
#define WHITE 0xFFFF
#define GREY 0x8410

// ARRAY TO REPLACE SINGLE DIGITS WITH LEADING ZEROES
char* leadingZero[] = {
  "00", "01", "02", "03", "04", "05", "06", "07", "08", "09"
};

//////VARIABLES TO HOLD COLOR VALUES///////////
int redValue = 0;
int grnValue = 0;
int bluValue = 0;

////////////////TFT SHIELD STUFF///////////////
//Use these pins for the shield!
#define sclk 52//13
#define mosi 50//11
#define miso 51 //not need
#define cs   10
#define dc   8
#define rst  0
//////////////////////////////////////////////

TimeChangeRule myDST = {"EDT", Last , Sun, Mar, 1, +60};    //Daylight time = UTC - 4 hours
TimeChangeRule mySTD = {"EST", Last, Sun, Oct, 1, 0};     //Standard time = UTC - 5 hours
Timezone myTZ(myDST, mySTD);


TimeChangeRule *tcr;        //pointer to the time change rule, use to get TZ abbrev
time_t utc, local;


int numberOfSensors = 4;

int lux, power;
float energy;

int RLux = 10;

char a[5];
char tempC[2];
char t[3];
char l[5];
char p[6];
char en[7];
char s[5];
char time[3];

char lastSb[5];

int LastValueSb;

char window = 1; // Saves menu position



unsigned long currentMillis;



unsigned long previousMillis = 0;
unsigned long timer1 = 0;


unsigned long previousMillis2 = 0;

boolean     firstTime = true;
boolean flagComplete;

boolean flagProgress = true;

// MORE SHIELD STUFF
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
//int position = 0;
//int dim = 255;
//int bright = 0;

int interval = 1000;
int interval2 = 10000;

//THIS LINE MAY VARY - SEE EXAMPLE SKETCHES FROM SHIELD
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);


///////////////GRAPH CONFIGURATIONS///////////////////
int blueDownLineY = tft.height(); //100
int blueUpLineY = 55;//45

int graphUpperLimit = blueUpLineY + 1;
int graphDownerLimit = blueDownLineY - 1;
int graphHeight = blueDownLineY - graphUpperLimit;

int xPos = 0;
int drawHeight;
int drawWidth;
int standby;
///////////////////////////////////////////////////////

int avg;
int sbTime = 10;
int x = 1;

int timer = 0;
int remTimeSec = sbTime - timer;



unsigned long totVal = 0;
int lastVal = 0;




//DEFINITIONS FOR THE JOYSTICK
#define Neutral 0
#define Press 1
#define Up 2
#define Down 3
#define Right 4
#define Left 5


long lastDebounceTime = 0;


boolean flag = true;
boolean change = true;

boolean avgFlag = false;

int sensorVal2;

int sensorPin = 9;
float voltage;




int lastChoiceMillis = 0; // a ultima vez que o pino de saida foi modificado (toggled)
int debounceDelay = 1000;
int number = 0;
int choiceDelay = 200;
int pinReadDelay     = 10;
int tempPin = 9;
int powerPin = 10;



void setup() {
  Wire.begin();
  Serial.begin(115200);


  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if (timeStatus() != timeSet)
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time");

  // MORE TFT STUFF - SEE EXAMPLE SKETCHES
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab

  //ROTATES DISPLAY 90 DEGREES FOR LANDSCAPE VIEW
  tft.setRotation(3);

  // analogWrite(5, 255);  //jump "LITE" and Digital pin 5 to dim

  // BLANKS OUT THE SCREEN AND DRAWS THE BLACK BAR
  tft.fillScreen(YELLOW);


  delay(1000);
}

void loop() {


  Serial.println(number);
  number++;
/*
  currentMillis = millis();

  if (currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;

    Serial.println();
    utc = now() + 3600; //- 3600L
    printTime(utc, "UTC");  //Prints UTC Time
    local = myTZ.toLocal(utc, &tcr);//
    printTime(local, tcr -> abbrev); //Prints Local Time

    sensorVal2 = analogRead(A2);

    voltage = sensorVal2 * 5.0;
    voltage /= 1024.0;

    if (avgFlag == true) {

      totVal += sensorVal2;
      avg = (totVal / x);
      x++;
      timer++;
    }

    xPos++;
  }


  if (currentMillis - previousMillis2 > interval2) {
    //readTemp();
    previousMillis2 = currentMillis;
  }





  int joy = CheckButton();

  switch (window) {  // Define checa qual tela atual


    case 1:          // executado quando na TELA 1

      switch (joy)
      {

        case Right:
          change = true;
          Set_window(2);
          break;

        default: Set_window(1);



      }

      break;

    case 2:          // executado quando na TELA 2
      switch (joy) {

        case Left:
          change = true;
          Set_window(1);
          break;

        case Right:
          change = true;
          Set_window(3);
          break;


        default: Set_window(2);

      }
      break;


    case 3:          // executado quando na TELA 3
      switch (joy) {

        case Left:
          change = true;
          Set_window(2);
          break;

        case Right:
          change = true;
          Set_window(4);

          break;

        default:;
          //Set_window(3);
      }
      break;


    case 4:          // executado quando na TELA 4
      switch (joy) {

        case Right:
          change = true;
          Set_window(5);
          break;

        case Left:
          change = true;
          Set_window(3);
          break;

        default:;

      }
      break;



(....a bunch of case statements.....don´t need to post her)



 
    case 10:          // executado quando na TELA 3
      switch (joy) {

        case Up:
          if (currentMillis - lastChoiceMillis > choiceDelay) {
            number++;
            //Serial.println(number, 4);
            lastChoiceMillis = currentMillis;
          }
          break;

        case Down:
          if (currentMillis - lastChoiceMillis > choiceDelay) {
            number--;
            if (number < 0) number = 0;
            //Serial.println(number, 4);
            lastChoiceMillis = currentMillis;
          }
          break;

        case Right:
          if (currentMillis - lastChoiceMillis > choiceDelay) {
            number = number * 10;
            //Serial.println(number, 4);
            lastChoiceMillis = currentMillis;
          }
          break;

        case Left:
          if (currentMillis - lastChoiceMillis > choiceDelay) {
            number = number * 0.1;
            //Serial.println(number, 4);
            lastChoiceMillis = currentMillis;
          }
          break;
      }


      break;

    default: ;
  }

*/


}

And I don't think I need to show you all of the functions! I think that's not the problem.

Even if I hide the rest of the code in the loop leaving just:

void loop() {
  Serial.println(number);
  number++;
}

I notice a break after 1 second..

And I don't think I need to show you all of the functions!

Since you don't know what the problem is, what you think is probably wrong.

It may be the PC.

This code

void loop() {
  Serial.println(number);
  number++;
}

will quickly overload the capacity of the Serial system because the Arduino works a great deal faster than the Serial system. For testing try adding a short delay().

...R

Weird as hell! I just restarted Arduino IDE, after a few times...it's working!