#include <LiquidCrystal.h>
int TrigPin = 4;
int EchoPin = 2;
int LedPin = 32;
int i = 0;
bool FullBool = false;
LiquidCrystal lcd(12, 14, 27, 26, 25, 33);
void setup()
{
Serial.begin(115200);
lcd.begin(16, 2);
pinMode(TrigPin, OUTPUT);
pinMode(LedPin, OUTPUT);
pinMode(EchoPin, INPUT);
lcd.print("Hello World");
}
void loop()
{
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
int duration = pulseIn(EchoPin, HIGH);
if (duration / 58 < 50)
{
lcd.clear();
lcd.print("Fulled");
digitalWrite(LedPin, HIGH);
lcd.setCursor(0, 1);
lcd.print("Fulled times = ");
lcd.print(i);
FullBool = true;
} else
{
if (FullBool)
{
i = i + 1;
Serial.print("Full Times = ");
Serial.print(i);
Serial.println(" times");
FullBool = false;
}
lcd.clear();
lcd.print("Not full");
digitalWrite(LedPin, LOW);
lcd.setCursor(0, 1);
lcd.print("Fulled times = ");
lcd.print(i);
}
Serial.print("Distance: ");
Serial.print(duration / 58);
Serial.println("cm");
delay(1000);
}