Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 20, 4);
- #define PIN_TRIG 12
- #define PIN_ECHO 11
- long duration, cm;
- void setup() {
- lcd.init();
- lcd.backlight();
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(PIN_TRIG, OUTPUT);
- pinMode(PIN_ECHO, INPUT);
- }
- void loop() {
- lcd.setCursor(6,0);
- lcd.print("Djarvis");
- lcd.setCursor(0,1);
- lcd.print("distance:");
- // put your main code here, to run repeatedly:
- digitalWrite(PIN_TRIG, LOW);
- delayMicroseconds(5);
- digitalWrite(PIN_TRIG, HIGH);
- delayMicroseconds(10);
- digitalWrite(PIN_TRIG, LOW);
- duration = pulseIn(PIN_ECHO, HIGH);
- cm = (duration/2) / 29.1;
- lcd.setCursor(9,1);
- lcd.print(cm);
- delay(400);
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement