Getting error code after days of using the same code? LCD Display I2c

Now I’ve been using variations of this code for the past couple of days, but suddenly I’m getting all these error messages stating:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

FinalProduct:112: error: 'lcd' does not name a type

     lcd.setCursor(0,3);

     ^

FinalProduct:113: error: 'lcd' does not name a type

     lcd.print(Time);

     ^

FinalProduct:116: error: expected unqualified-id before 'if'

     if (now.hour() > 6 && now.hour() < 18){

     ^

exit status 1
'lcd' does not name a type

I can’t seem to find anything helpful online, so this is me being desperate.

This is my code:

//Import af diverse biblioteker
#include <SPI.h>
#include <Wire.h>
#include <RTClib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>

//Defineringer af temperatur
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celcius = 0;

//Definering af LCD display
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
int count = 0;
float p = 0;

//Definering af Real Time Clock (RTC)
RTC_DS1307 rtc;

//Defineringer af pH-måler
const int analogInPin = A0;
int sensorValue = 0;
unsigned long int avgValue;
int buf[10];

//Digital modstand
byte address = 0x11;
int CSG = 10; //Gult lys
int CSH = 5; //Hvidt lys

//Setup
void setup(void)
{
    Serial.begin(9600);
    SPI.begin(); //Digital modstand
    pinMode (3, OUTPUT); //Digital modstand
    pinMode (6, OUTPUT); //Digital modstand
    pinMode (5, OUTPUT); //Hvidt lys
    pinMode (9, OUTPUT); //CO2-dysse
    pinMode (10,OUTPUT); //Gult lys
    sensors.begin(); //Termometer
    lcd.begin (20,4); //LCD
    lcd.setBacklight(HIGH); //LCD
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Real Time Clock
}

//Program
void loop(void){ 
    //Temperatur
    sensors.requestTemperatures(); 
    Celcius = sensors.getTempCByIndex(0);

    //pH
    for (int i = 0; i < 10; i++){ //Tager gennemsnittet af 10 målinger fra analogInPin
    buf[i] = analogRead(analogInPin);
    delay(10);}    
    for (int i = 0 ; i < 9; i++){
        for (int j = i + 1; j < 10; j++){
            if (buf[i] > buf[j]){
                buf[i] = buf[j];}}}                
    avgValue=0;
    for (int i = 2; i < 8; i++)
    avgValue+=buf[i];    
    float pHVol = (float)avgValue * 5.0 / 1024 /6;
    float phValue = -5.70 * pHVol + 21.6;

    //Tid
    DateTime now = rtc.now();
    String Hour = String(now.hour());
    String Minute = String(now.minute());
    String Second = String(now.second());
    if (now.hour() < 10){
        Hour = "0" + String(now.hour());}
    if (now.minute() < 10){
        Minute = "0" + String(now.minute());}
    if (now.second() < 10){
        Second = "0" + String(now.second());}
    String Time = "Time: " + Hour + ":" + Minute + ":" + Second + " ";

    //Lys
    if (now.hour() > 6 && now.hour() < 12){
        //lightFunction(30%-100%);
        }
    if (now.hour() > 12 && now.hour() < 15){
        //lightFunctionG(255);
        //lightFunctionH(255);
        }
    if (now.hour() > 15 && now.hour() < 20){
        //lightFunction(100%-30%);
        }
    if (now.hour() > 20 && now.hour() < 6){
        //lightFunction(0%);
        }
//    if (now.hour() > TestTid && now.hour() < TestTid){
//        //lightFunction(0%);
//        }
          
    //LCD
    //Temperatur
    lcd.setCursor(0,0);
    lcd.print("Temp: "+String(Celcius)+" deg C");
    //pH-værdi
    lcd.setCursor(0,1);
    lcd.print("pH-value: "+String(phValue)+" ");
    //Lysstyrke
    lcd.setCursor(0,2);
    lcd.print("Brightness: "+String(100)+"% ");}
    //Tid
    lcd.setCursor(0,3);
    lcd.print(Time);

    //USB
    if (now.hour() > 6 && now.hour() < 18){
        if(phValue > 7.3){
            digitalWrite(9,HIGH); //Tænder for CO2-dysse
            delay(100);
            digitalWrite(9,LOW);}} //Slukker for CO2-dysse
    
    delay(300);}

//Lys funktioner
int lightFunctionG(int value){ //Gult lys
    digitalWrite(CSG, LOW);
    SPI.transfer(address);
    SPI.transfer(value);
    digitalWrite(CSG, HIGH);}
int lightFunctionH(int value){ //Hvidt lys
    digitalWrite(CSH, LOW);
    SPI.transfer(address);
    SPI.transfer(value);
    digitalWrite(CSH, HIGH);}

Any idea about what to do?

You have a spurious closing } here I think:

   lcd.setCursor(0,2);
    lcd.print("Brightness: "+String(100)+"% ");} //<<<<<<<<<<<<<<<<<<<<<
    //Tid
    lcd.setCursor(0,3);

;}}} That should never, ever happen.

Nevermind - did a CTRL+t and realized a } (curly bracket) in the middle of my code. It works now!

-Just saw neiklot pointed it out as well.

--AWOL, I know, but I'm trying to cram the lines :smiley:

DatCapriz:
--AWOL, I know, but I'm trying to cram the lines

Don't

void loop(void){ 
        for (int j = i + 1; j < 10; j++){
            if (buf[i] > buf[j]){
                buf[i] = buf[j];}}}

Your code is VERY hard to read.

Put EVERY { on a line BY ITSELF.
Put EVERY } on a line BY ITSELF.
Use Tools + Auto Format, to properly indent your code.

If that doesn’t reveal what the problem is, post the revised code.