Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define trigPin 12
- #define echoPin 13
- #define MAX_DISTANCE 35
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <LcdBarGraphRobojax.h>
- LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
- LcdBarGraphRobojax lbg(&lcd, 16, 0, 0);
- void setup()
- {
- lcd.begin(); // initialize the lcd
- lcd.backlight();
- lcd.setCursor(0, 1);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- }
- void loop()
- {
- long duration, distance;
- digitalWrite(trigPin, LOW); // Added this line
- delayMicroseconds(2); // Added this line
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10); // Added this line
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = duration*0.034/2;
- lbg.clearLine(1);
- lbg.drawValue( 10, duration*0.034/2); //Jika value sepuluh 10 atau batas cm di tukar dengan duration sebelahnya maka graph aka terbalik dari kecil ke besar
- delay(100);
- lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
- lcd.print("Distance: "); // Prints string "Distance" on the LCD
- lcd.print(distance); // Prints the distance value from the sensor
- lcd.print(" cm ");
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement