Created
December 11, 2016 19:27
-
-
Save WlascicielBMW/20f0333cdf284343841c72a6e4ba7814 to your computer and use it in GitHub Desktop.
Arduino MEGA HC-SR04 + LCD 162 I2C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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