Skip to content

Instantly share code, notes, and snippets.

@MichaelBell
Created October 20, 2025 22:28
Show Gist options
  • Select an option

  • Save MichaelBell/7ba32507869c055efcfcd37201d4891c to your computer and use it in GitHub Desktop.

Select an option

Save MichaelBell/7ba32507869c055efcfcd37201d4891c to your computer and use it in GitHub Desktop.
from time import sleep_ms, sleep_us
from micropython import const
from machine import ADC, Pin
import rp2
import ttcontrol
a0 = ADC(Pin(45))
def read_ap():
return a0.read_u16() * 3.3 / 65535
H_GATE = []
H_GATE.append(ttcontrol.uio[5])
H_GATE.append(ttcontrol.uio[2])
H_GATE.append(ttcontrol.ui_in[1])
V_GATE = []
V_GATE.append(ttcontrol.uio[6])
V_GATE.append(ttcontrol.uio[3])
V_GATE.append(ttcontrol.uio[0])
HD_RES = ttcontrol.ui_in[4]
HD_SHORT = ttcontrol.ui_in[3]
HD_LINE = ttcontrol.ui_in[2]
HD = [HD_RES, HD_SHORT, HD_LINE]
VD_RES = ttcontrol.ui_in[7]
VD_SHORT = ttcontrol.ui_in[6]
VD_LINE = ttcontrol.ui_in[5]
VD = [VD_RES, VD_SHORT, VD_LINE]
RES = const(0)
SHORT = const(1)
LINE = const(2)
H_INPUT = []
H_INPUT.append(ttcontrol.ui_in[0])
H_INPUT.append(ttcontrol.proj_rst_n)
H_INPUT.append(ttcontrol.clk_pin)
V_INPUT = []
V_INPUT.append(ttcontrol.uio[7])
V_INPUT.append(ttcontrol.uio[4])
V_INPUT.append(ttcontrol.uio[1])
def enable_hv_latch(h, v):
H_GATE[h].on()
V_GATE[v].on()
def disable_latches():
for i in range(3):
H_GATE[i].off()
V_GATE[i].off()
def set_hd_vd(h, v, setting_h, setting_v):
enable_hv_latch(h, v)
if setting_h is not None:
HD[setting_h].on()
if setting_v is not None:
VD[setting_v].on()
sleep_us(100)
disable_latches()
sleep_us(100)
if setting_h is not None:
HD[setting_h].off()
if setting_v is not None:
VD[setting_v].off()
def init():
# Design 0 doesn't drive the bidirs, select it
ttcontrol.select_design(0)
# Enable all inputs and set them all low
ttcontrol.enable_ui_in(True)
ttcontrol.enable_uio_in((True,)*8)
disable_latches()
for i in range(3):
HD[i].off()
VD[i].off()
H_INPUT[i].off()
V_INPUT[i].off()
for h in range(3):
for v in range(3):
set_hd_vd(h, v, None, None)
# Select design
ttcontrol.select_design(482)
init()
# Simple voltage divider
set_hd_vd(0, 0, RES, RES)
set_hd_vd(0, 1, RES, None)
set_hd_vd(0, 2, RES, None)
set_hd_vd(1, 0, None, RES)
set_hd_vd(2, 0, None, RES)
print(read_ap())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment