from machine import Pin, I2C
import ssd1306
import machine
tim = machine.Timer(-1)
sw1 = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_UP)
sw2 = machine.Pin(23, machine.Pin.IN, machine.Pin.PULL_UP)
led = machine.Pin(18, machine.Pin.OUT)
#กำหนดขา ESP32
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_hight = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_hight, i2c)
def onLed(t):
oled.fill(0)
led.value(1)
oled.text('LED = On', 0, 10)
oled.show()
def offLed(t):
oled.fill(0)
led.value(0)
oled.text('LED = Off', 0, 10)
oled.show()
sw1.irq(trigger = machine.Pin.IRQ_FALLING, handler = onLed)
sw2.irq(trigger = machine.Pin.IRQ_FALLING, handler = offLed)