LCD only prints on 2nd line if called in loop()

Hello everyone, I come in seek of your eternal knowledge…
I recently bough a 16x2 LCD equipped with it’s own I2C for a proyect I’m making, and I got off with it just fine. Made special characters and all!
But I came across an unexplicable fault that for the life of me I cannot understand and couldn’t find the answer for it on the internet. Just a head’s up, I don’t know the model number for neither the LCD or the I2C.

I need to keep tabs on three things: temperature, light on/off, and fan on/off (or heater on/off, it just replaces the “fan on/off” text).
The temperature is always shown on the first line (0, 0) and it works great, I’ve had no errors whatsoever with that.
The light status shows on the second line to the left (0, 1), and the fan/heater status on the same line but to the right (9, 1).

Now, when firstly testing this I skipped the measureTemp() call on loop() and replaced it with updateLCD(), to make sure everything displays right and stuff, and so it did. All information was displayed properly. Now that’s done, so I went back to my original code which needs to read temperature first (measureTemp()), average the readings (tempAverage()), and then update the LCD (updateLCD())… that seems like a big no-no.

The second line won’t appear when compiling the code as shown here.
Sometimes the word “Luz:” (“Light:”) appears shortly but on the right-side instead of the left-side of the second line, and nothing else shows on that line!! :o

I have no idea what to make of this. The code works great aside from that, the setCursor() syntax works good, so does the print(), and all other syntaxes used. Nevertheless, unless called from loop() as explained earlier, the second line won’t show.

I’ve commented on the key lines.

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

LiquidCrystal_I2C lcd(0x3F, 16, 2);

float temp;
float tempValues[6] = {0, 1, 2, 3, 4, 5};
int tempIndex = 0;

float avg;
float avgValues[5] = {0, 1, 2, 3, 4};
int avgIndex = 0;

float limit;

char* state[] = {"ON", "OFF"};

unsigned long fiveSecThresh = 5000;
unsigned long tenSecThresh = 10000;

byte degree[8] = {

void setup() {
  lcd.begin(16, 2);
  lcd.createChar(0, degree);
  lcd.setCursor(3, 0);
  lcd.setCursor(4, 1);

void loop() {
  measureTemp();   //Go straight to measuring temperature

void measureTemp() {
  temp = (0.50 * analogRead(A0));
  tempValues[tempIndex] = temp;
  while (millis() % tenSecThresh <= fiveSecThresh);
  // Wait 5 sec
  temp = (0.50 * analogRead(A0));
  tempValues[tempIndex] = temp;
  while (millis() % tenSecThresh >= fiveSecThresh);
  // Wait 5 sec

  if (tempIndex == 6 || tempIndex > 6) {
    tempIndex = 0;
    tempAverage();    //6 measurements in 60 seconds. Now go average them

void tempAverage() {
  avg = tempValues[0] + tempValues[1] + tempValues[2] + tempValues[3] + tempValues[4] + tempValues[5];
  avg = avg / 6;

  avgValues[avgIndex] = avg;

  if (avgIndex == 5 || avgIndex > 5) {
    avgIndex = 0;
    avgLimit();    //Done averaging, check limits
  updateLCD();    //With the "limits" value calculated, print it all out on the LCD

void avgLimit() {    //Average the last 5 averages done (30 measurements in total)
  limit = avgValues[0] + avgValues[1] + avgValues[2] + avgValues[3] + avgValues[4];
  limit = limit / 5;

void updateLCD() {
  lcd.clear();                 //
  lcd.print("Temp:");       //
  lcd.setCursor(7, 0);     //
  lcd.print(avg);         //
  lcd.setCursor(12, 0);   //
  lcd.write(byte(0));      //
  lcd.setCursor(13, 0);   //
  lcd.print("C");         //This is always shown without error nor fault

  lcd.setCursor(0, 1);    //This point onwards works when updateLCD() is callen in loop()
  lcd.print("Luz:");        //but doesn't work when called like shown
  lcd.setCursor(4, 1);
  lcd.print(state[1]); /*placeholder*/

  lcd.setCursor(9, 1);  
  if (limit < 21.00) {          //Too cold, turn on heat
    lcd.setCursor(13, 1);
  } else if (limit > 25.00) {   //Too hot, turn on fans
    lcd.setCursor(13, 1);

Thanks to everyone in advance!