#include <LiquidCrystal_I2C.h>
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
int trig = 5;
int echo = 18;
float sp;
float lecture_echo;
float ds;
String output;
void setup()
{
SerialBT.begin("ESP32-Bluetooth20250402D");
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
pinMode(echo, INPUT);
Serial.begin(115200);
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
void loop()
{
if(SerialBT.available()) {
output=SerialBT.readString();
ds = output.toFloat();
// output = Serial.readString();
// Serial.println(output);
// ds = output.toFloat();
Serial.println(ds);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
lecture_echo = pulseIn(echo, HIGH);
sp = ((ds/100) / (lecture_echo/1000000)) * 2;
Serial.print("Speed: ");
Serial.println(sp);
// set cursor to first column, first row
lcd.setCursor(0, 0);
// print message
lcd.print("SpeedOfSound=");
delay(1000);
// clears the display to print new message
// lcd.clear();
// set cursor to first column, second row
lcd.setCursor(0,1);
lcd.print(sp);
delay(1000);
lcd.clear();
delay(1000);
}
}
Σχόλια
Δημοσίευση σχολίου