//#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int lcdColumns=16;
int lcdRows=2;
const int trigPin = 5;
const int echoPin = 18;
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
long duration;
float distanceCm=1;
float distanceInch=1;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
void setup() {
lcd.init();
// turn on LCD backlight
lcd.backlight();
//Wire.begin();
//Serial.println("\nI2C Scanner");
// put your setup code here, to run once:
//Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(26, OUTPUT);
// pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
//pinMode(echoPin, INPUT);
}
void loop() {
lcd.setCursor(0, 0);
// print message
lcd.print("Hello, World!");
delay(1000);
// clears the display to print new message
lcd.clear();
// set cursor to first column, second row
lcd.setCursor(0,1);
lcd.print("Hello, World!");
delay(1000);
lcd.clear();
// byte error, address;
// int nDevices;
// Serial.println("Scanning...");
// nDevices = 0;
// for(address = 1; address < 127; address++ ) {
// Wire.beginTransmission(address);
// error = Wire.endTransmission();
// if (error == 0) {
// Serial.print("I2C device found at address 0x");
// if (address<16) {
// Serial.print("0");
// }
// Serial.println(address,HEX);
// nDevices++;
// }
// else if (error==4) {
// Serial.print("Unknow error at address 0x");
// if (address<16) {
// Serial.print("0");
// }
// Serial.println(address,HEX);
// }
// }
// if (nDevices == 0) {
// Serial.println("No I2C devices found\n");
// }
// else {
// Serial.println("done\n");
// }
// delay(5000);
digitalWrite(26, HIGH);
// // put your main code here, to run repeatedly:
delay(1000);
digitalWrite(26, LOW);
delay(1000); // this speeds up the simulation
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
//Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// // Reads the echoPin, returns the sound wave travel time in microseconds
// duration = pulseIn(echoPin, HIGH);
// // Calculate the distance
// distanceCm = duration * SOUND_SPEED/2;
// // Convert to inches
// distanceInch = distanceCm * CM_TO_INCH;
// // Prints the distance in the Serial Monitor
// Serial.print("Distance (cm): ");
// Serial.println(distanceCm);
// Serial.print("Distance (inch): ");
// Serial.println(distanceInch);
// delay(1000);
}