from machine import Pin, I2C
import ssd1306
import utime
# ESP32 Pin assignment
i2c = I2C(0, scl=Pin(9), sda=Pin(8))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
oled.text('Hello, Wokwi!', 10, 10)
oled.show()
print("Hello, ESP32-S3!")
keyMatrix = [
[ "F1", "F2", "F3"],
[ "Left", "Up", "F4"],
[ "Down", "*", "Right"]
]
colPins = [7,15,16]
rowPins = [6,5,4]
row = []
column = []
for item in rowPins:
row.append(machine.Pin(item,machine.Pin.OUT))
for item in colPins:
column.append(machine.Pin(item,machine.Pin.IN,machine.Pin.PULL_DOWN))
key = '0'
def scanKeypad():
global key
for rowKey in range(5):
row[rowKey].value(1)
for colKey in range(4):
if column[colKey].value() == 1:
key = keyMatrix[rowKey][colKey]
row[rowKey].value(0)
return(key)
row[rowKey].value(0)
def printKey():
key=scanKeypad()
if key is not None:
print("Key pressed is:{}".format(key))
utime.sleep(0.2)
while True:
printKey()