print("HEIGHT MEASUREMENT")

#IMPORT THE MODULES/LIBRARY
import hcsr04 #ultrasonic sensor library
import ssd1306 #oled
from machine import SoftI2C,Pin,PWM
from utime import sleep

#to create object for ultrasonic sensor using oop---library.class name ()
ultrasonic_sensor = hcsr04.HCSR04(trigger_pin=5, echo_pin=18, echo_timeout_us=500*2*30) #range trigger


#OLED
i2c_oleddisplay = SoftI2C(scl=Pin(22),sda=Pin(21))
oled_width = 128
oled_height = 64

oled = ssd1306.SSD1306_I2C(oled_width, oled_height,i2c_oleddisplay)


#display the information from ultrasonic

distance_in_cm = ultrasonic_sensor.distance_cm()
distance_in_mm = ultrasonic_sensor.distance_mm()

#display the range on seriel monitor
print ('Your Height is detected : ',distance_in_cm,'cm')
print ('Your Height is detected : ',distance_in_mm,'mm')

#display the range on OLED
oled.fill(1)
oled.text('Your Height is:',3,0,0)
oled.text(str(distance_in_cm),5,20,0)
oled.text('cm', 75,20,0)
oled.text(str(distance_in_mm),5,40,0)
oled.text('mm', 75,40,0)
oled.show()