-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistance_show_on_LCD.ino
More file actions
53 lines (45 loc) · 1.09 KB
/
Distance_show_on_LCD.ino
File metadata and controls
53 lines (45 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//Simulation Link: https://www.tinkercad.com/things/9gk5LzJxw1R-hw-02?sharecode=aEn7UnBIqnXBVUDwBZCgGtNMOzQ3nYSqFXzoGff3ixU
#include <Adafruit_LiquidCrystal.h>
const int trigPin = 6, echoPin = 7;
long time;
int cm, inch;
Adafruit_LiquidCrystal lcd(0);
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.setBacklight(1);
lcd.begin(16,2);
lcd.print("LCD & Ultrasonic");
lcd.setCursor(4,1);
lcd.print("cm & inch");
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
time = pulseIn(echoPin, HIGH);
cm = time*0.0343/2;
inch = time*0.0133/2;
lcd.setCursor(0,1);
lcd.print(cm);
if(cm<10) {
lcd.setCursor(1,1);
lcd.print(" ");
}
if(cm<100) {
lcd.setCursor(2,1);
lcd.print(" ");
}
lcd.setCursor(9,1);
lcd.print(inch);
if(inch<10) {
lcd.setCursor(10,1);
lcd.print(" ");
}
if(inch<100) {
lcd.setCursor(11,1);
lcd.print(" ");
}
}