from machine import Pin, ADC, I2C
import time
from sh1107 import SH1107_I2C # Use your provided SH1107 driver
# Setup I2C for SH1107 OLED
i2c = I2C(0, scl=Pin(1), sda=Pin(0)) # GP1=SCL, GP0=SDA
oled = SH1107_I2C(128, 128, i2c, address=0x3C, rotate=0) # 128x128, 0° (upright), corrected parameter
# Setup components
button = Pin(6, Pin.IN, Pin.PULL_UP) # GP6 for piezo tap simulation
pot = ADC(Pin(26)) # GP26 for potentiometer
# Initial state
last_time = 0
# Clear the OLED display
oled.fill(0)
oled.contrast(255)
oled.show()
while True:
# Check button press to update voltage
if button.value() == 0 and time.ticks_ms() - last_time > 200: # Debounce 200ms
last_time = time.ticks_ms()
pot_value = pot.read_u16() # Read pot setting
voltage = (pot_value / 65535) * 3.3 # Convert to 0-3.3V based on pot
oled.fill(0) # Clear screen
oled.text("Sim Voltage:", 32, 32, 1) # Shifted position
oled.text("{:.2f}V".format(voltage), 32, 47, 1) # Shifted position
oled.show()
time.sleep(0.01) # Small delay
Loading
grove-oled-sh1107
grove-oled-sh1107