Skip to content

Instantly share code, notes, and snippets.

@WlascicielBMW
Created December 11, 2016 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WlascicielBMW/20f0333cdf284343841c72a6e4ba7814 to your computer and use it in GitHub Desktop.
Save WlascicielBMW/20f0333cdf284343841c72a6e4ba7814 to your computer and use it in GitHub Desktop.
Arduino MEGA HC-SR04 + LCD 162 I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define TRIG 4
#define ECHO 5
LiquidCrystal_I2C lcd(0x3f,2,16);
void setup()
{
pinMode(TRIG,OUTPUT);
pinMode(ECHO,INPUT);
lcd.init();
lcd.backlight();
}
float pomiar(){
unsigned long czas;
digitalWrite(TRIG,HIGH);
delayMicroseconds(10);
digitalWrite(TRIG,LOW);
czas = pulseIn(ECHO,HIGH);
return czas / 58.00;
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("POMIAR=");
lcd.setCursor(7,0);
lcd.print(pomiar());
lcd.setCursor(13,0);
lcd.print("cm");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment