I want if i push the button that it only renew the value on the lcd then
somebody that know how i have to do it
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int trigPin = 9; // TRIG pin
int echoPin = 8; // ECHO pin
int buttonpin = 2;
float duration_us, distance_cm;
void setup()
{
Serial.begin(9600); //Serial baud rate
lcd.begin (16,2);
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.home ();
lcd.print(distance_cm);
delay(2000);
lcd.clear();
// configure the trigger pin to output mode
pinMode(trigPin, OUTPUT);
// configure the echo pin to input mode
pinMode(echoPin, INPUT);
pinMode(buttonpin, INPUT);
;
}
void loop()
{
// generate 10-microsecond pulse to TRIG pin
digitalWrite(trigPin, HIGH);
delayMicroseconds(10000);
digitalWrite(trigPin, LOW);
// measure duration of pulse from ECHO pin
duration_us = pulseIn(echoPin, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
delay(5000);
// print the value to Serial Monitor
lcd.print(distance_cm);
delay(5000);
//if (digitalRead(buttonpin)==HIGH){
lcd.clear();
//}
}