New to all this and trying to write a sketch to measure distance with an RTF 04 and display it on the PC and an LCD. The code below produces the error message “LCD was not declared in this scope” on either of the two lines which set the cursor and write the variable distance. If I comment thes out, everything else works. Tried this the other day and it worked. I cannot for the life of me find what I have done which is different (probably staring me in the face). The code is as follows:
#define ECHOPIN 8 // Pin to receive echo pulse
#define TRIGPIN 9 // Pin to send trigger pulse
#include <LiquidCrystal.h>
void setup(){
Serial.begin(9600);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("Distance = ");
}
void loop(){
digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW); // Send pin low again
int distance = pulseIn(ECHOPIN, HIGH); // Read in times pulse
distance= distance/58; // Calculate distance from time of pulse
Serial.println(distance);
delay(50);
lcd.cursor(0,12); //Move cursor to one space after equals sign
lcd.print(distance); // Wait 50mS before next ranging
}