I've been trying to make my code display a message if a condition is met, everything else is working well and I have plugged everything according to order but it tells me that lcd does not name any type, so far I've been told to put "lcd" besides the parenthesis of the "liquid crystal" line and switch the line to the setup loop, but the error still shows up, anyone got any idea what this could entail and how to fix it?
#include <Servo.h>
#include <LiquidCrystal.h>
#define echo 6
#define trig 7
//lcd
#define lcd_E 8
#define lcd_4 10
#define lcd_5 11
#define lcd_6 12
#define lcd_7 13
#define lcd_RS 5
LiquidCrystal lcd(lcd_RS, lcd_E, lcd_4, lcd_5, lcd_6, lcd_7);
Servo servo;
float duration, distance;
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
servo.attach(9);
}
void loop() {
// Print a message to the LCD.
// put your main code here, to run repeatedly:
Sonic();
if (distance < 10) {
wave();
Sonic();
lcd.print("hello, world!");
} else {
servo.write(150);
lcd.print("waiting...");
}
}
void Sonic() {
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = (duration * .0343) / 2;
Serial.print("Distance: ");
Serial.println(distance);
delay(100);
}
void wave() {
Serial.println("waving");
servo.write(0);
delay(100);
servo.write(90);
delay(100);
}