// C++ code
// THE BELOW CODE MAY SEEM LIKE NOT WORKING, BUT ACUALLY WORKS!
#include
#include
#include
// #include
const byte I2C_ADDR = 0x27;
const byte LCD_COLUMNS = 16;
const byte LCD_LINES = 2;
LiquidCrystal_I2C lcd_1(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int trigger = 7;
int echo = 6;
// Adafruit_LiquidCrystal lcd_1(0x27);
void setup()
{
Serial.begin(9600);
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
pinMode(echo, INPUT);
lcd_1.begin(16, 2);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pinMode(2, INPUT);
pinMode(8,INPUT)
}
void loop()
{
float cm = 0;
double time = 0;
digitalWrite(7, HIGH);
delayMicroseconds(2);
digitalWrite(7,LOW);
time = pulseIn(echo, HIGH);
cm = time*29/2*0.0473/100*2.511111;
Serial.println(cm);
lcd_1.setCursor(0, 0);
lcd_1.setBacklight(1);
lcd_1.print("cm: ");
lcd_1.setCursor(0, 1);
lcd_1.print(cm);
lcd_1.print("cm +-0.1cm");
delayMicroseconds(1000);
}