print("oled , servo dgn ultrasonoic")

from machine import Pin, PWM , SoftI2C
from utime import sleep
import library_servo
import library_ultrasonic
import SSD1306

# declare pin
motor = PWM(Pin(27, Pin.OUT))   # air sejuk
TRIG = Pin(33, Pin.IN)
ECHO = Pin(32, Pin.OUT)
i2c_oled = SoftI2C(scl=Pin(22), sda=Pin(21)) 
oled_width = 128
oled_height = 64


srvo = library_servo.Servo(27)
ultra_sensor = library_ultrasonic.HCSR04(trigger_pin=TRIG, echo_pin=ECHO)
screen = SSD1306.SSD1306_I2C(width = oled_width, height = oled_height, i2c = i2c_oled)
distance_incm = ultra_sensor.distance_cm()

#main coding
while True:
  if distance_incm >= 50:
    srvo.move(90)
    screen.text("selamat datang", 5, 10, 0) #text, column, color
    screen.show()    
    sleep(0.5)
    screen.fill(1)


  else:
    srvo.move(0)


Loading
esp32-devkit-v1