'''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