//Include LCD library
#include <LiquidCrystal_I2C.h>
#include <HCSR04.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,16,2);
UltraSonicDistanceSensor distanceSensor(A0,A1);
float distance;
float boxHeight = 185.0;
int buzzerPin= 8;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(buzzerPin, OUTPUT);
printInstructions();
}
void loop() {
distance = distanceSensor.measureDistanceCm();
Serial.println(distance);
delay(1000);
/*
lcd.clear();
lcd.setCursor(0,0);
lcd.print(distance);
*/
if (distance < 65 ) {
printHeight();
delay(1000);
tone(buzzerPin, 1000);
delay(1000);
noTone(buzzerPin);
delay(5000);
} else {
printInstructions();
}
}
void printInstructions() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Stand under the");
lcd.setCursor(0,1);
lcd.print("box!");
}
void printHeight() {
int heightInCm = boxHeight - distance;
int heightInInches = heightInCm/1;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Height:");
lcd.setCursor(8,0);
lcd.print(heightInInches);
lcd.setCursor(11,0);
lcd.print("IN");
lcd.setCursor(0,1);
//lcd.print(distance);
}