Skip to content

Instantly share code, notes, and snippets.

@todbot
Created October 15, 2024 22:37

Revisions

  1. todbot created this gist Oct 15, 2024.
    33 changes: 33 additions & 0 deletions touchio_debug_code.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # touchio_debug_code.py -- debug raw touchio values
    # 15 Oct 2024 - @todbot / Tod Kurt
    # This sketch shows the raw_value and threshold value for each
    # touchio TouchIn input, as well as the normal ".value" boolean
    # Hopefully this will help to debug touchio circuits.

    import time
    import board
    import touchio

    # these pins are for the first 8 picotouch midi board pads,
    # your board will likely use different pins
    touch_pins = (
    board.GP0, board.GP1, board.GP2, board.GP3,
    board.GP4, board.GP5, board.GP6, board.GP7,
    )

    touch_ins = [] # holder of all the touchio objects
    for pin in touch_pins:
    print("creating TouchIn for pin", pin)
    touch_in = touchio.TouchIn(pin)
    touch_ins.append(touch_in)

    while True:
    # print out threshold and raw value for each pin
    for i, touch_in in enumerate(touch_ins):
    raw_value = touch_in.raw_value
    threshold = touch_in.threshold
    touched = touch_in.value # same as "if raw_value > threshold"
    touched_str = "*" if touched else " "
    print("%4d/%4d%s " % (raw_value, threshold, touched_str), end='')
    print()
    time.sleep(0.1)