'''Write a micropython script to display "Esp32 with LCD " on  I2c 16*2 LCD and "ESP32 with Oled" on 
oled display'''
import machine
from machine import Pin, SoftI2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import ssd1306
from time import sleep
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000)
I2C_ADDR = 0x3c
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c, I2C_ADDR)
oled.text('Esp32 with oled', 0, 0, 1) #for making color black use 1 at third position and 
oled.show()
I2C_ADDR = 0x27
totalRows = 2
totalColumns = 16
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000)
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns)
lcd.putstr("Esp32 with LCD")
   







# ur with library wala h
"""from hcsr04 import HCSR04
from time import sleep

sensor = HCSR04(trigger_pin=5,echo_pin=18,echo_timeout_us=10000)

while True:
    distance=sensor.distance_cm()
    print("Distance:",distance,'cm')
    sleep(1)"""
import machine
from machine import Pin, ADC, PWM
from time import sleep_us, sleep
trigger=Pin(5,Pin.OUT)
echo = Pin(18,Pin.IN)
while True:
    trigger.value(0)
    sleep(2)
    trigger.value(1)
    sleep(10) 
    trigger.value(0)

    t=machine.time_pulse_us(echo,1)
    d = (t*0.0343)/2
    print("Distance:",d)
    sleep(1)


    #displayig the temprature and humidity on i2c led and oled
    #display the distance on oled and i2c





esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA