'lcd' does not name a type

include <LiquidCrystal.h>

I have the following code for a freqency meter. When I compile the code I get the failure message concerning the last 3 lines of the code: Compilation error: 'lcd' does not name a type

Can somebody help me with this matter?

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcd(14,7,6,5,4,3,2);

#define pulse_ip 14

int ontime, offtime;

float freq, period;



void setup(){

 lcd.begin(16,2);

 lcd.print("Freq:");

 lcd.clear();  

}




void loop() {

ontime = pulseIn(pulse_ip, HIGH);

offtime = pulseIn(pulse_ip, LOW);

period = ontime + offtime;

freq = 1000000 / period;

}

  

  lcd.setCursor(5, 0);

  lcd.print(freq);

  lcd.print("Hz")

Welcome to the forum

You have 3 lines of code at the end of the sketch that are not in a function, hence the error

Look carefully where the closing brace of the loop() function code block is in the code

You will not see errors from these two lines (above), but they will cause your project to fail.

The variables rs, en, and d4 through d7 were given values (pin numbers).
In the "object/instance creation" line, you should use those previously defined variable names.

For example:

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // pin number variable names
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // object/instance "lcd" creation 

You can see the "14" being used in the next line for the definition of pulse_ip