Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_PCF8574.h>
  3.  
  4. LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display
  5.  
  6. const int trigPin = 12;
  7. const int echoPin = 11;
  8.  
  9. void setup()
  10. {
  11.  
  12. Serial.begin(115200);
  13. while (! Serial);
  14. Wire.begin();
  15. Wire.beginTransmission(0x27);
  16.  
  17. lcd.begin(16, 2);
  18. pinMode(trigPin, OUTPUT);
  19. pinMode(echoPin, INPUT);
  20.  
  21. Serial.println("LCD...");
  22. }
  23. int getDist(){
  24.  
  25. digitalWrite(trigPin, LOW);
  26. delayMicroseconds(2);
  27.  
  28. digitalWrite(trigPin, HIGH);
  29. delayMicroseconds(10);
  30.  
  31. digitalWrite(trigPin, LOW);
  32. return (pulseIn(echoPin, HIGH) / 58.2);
  33.  
  34. }
  35. void loop()
  36. {
  37. lcd.setBacklight(255);
  38. lcd.home(); lcd.clear();
  39. lcd.print( getDist() );
  40. lcd.print( " cm distance" );
  41. delay(300);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement