Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ code
- // https://learn.adafruit.com/i2c-spi-lcd-backpack/arduino-i2c-use
- #include <Adafruit_LiquidCrystal.h>
- int seconds = 0;
- int trigger = 6;
- int echo = 2;
- Adafruit_LiquidCrystal lcd_1(0);
- void setup()
- {
- lcd_1.begin(16, 2);
- lcd_1.print("hello world");
- pinMode(trigger,OUTPUT);
- pinMode(echo,INPUT);
- }
- void loop()
- {
- float distance = 0.0;
- float finalvalue = 0.0;
- digitalWrite(trigger,LOW);
- delayMicroseconds(4);
- digitalWrite(trigger,HIGH);
- delayMicroseconds(10);
- digitalWrite(trigger,LOW);
- distance = pulseIn(echo,HIGH);
- finalvalue = (distance/28.57)/2;
- lcd_1.setCursor(0, 1);
- lcd_1.print(finalvalue);
- seconds += 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement