# rp_touchy_serial_demo.py for HackerBoxes 0110 rp-touchy board
#
# based on Tod Kurt's slider_test.py found here:
#   https://github.com/todbot/picoslidertoy
#
# modifications:
#   pins changed to match HackerBox board
#   removed ssd1306 display
#   added print to serial output
#

import time, math
import board
import touchio
import busio
import displayio
import vectorio

from touchslider import TouchWheel, TouchSlider

fader1_pins = (board.GP0, board.GP1, board.GP2)
fader2_pins = (board.GP5, board.GP4, board.GP27)
fader3_pins = (board.GP9, board.GP10, board.GP21)
fader4_pins = (board.GP15, board.GP11, board.GP18)
rotary1_pins = (board.GP13, board.GP14, board.GP12)
rotary2_pins = (board.GP6, board.GP7, board.GP8)
pad_pins = (board.GP28, board.GP3, board.GP26, board.GP22,
            board.GP20, board.GP19, board.GP17, board.GP16)

faders = (
    TouchSlider(fader1_pins),
    TouchSlider(fader2_pins),
    TouchSlider(fader3_pins),
    TouchSlider(fader4_pins),
)

wheel1 = TouchWheel(rotary1_pins)
wheel2 = TouchWheel(rotary2_pins)

pads = []
for pin in pad_pins:
    pads.append(touchio.TouchIn(pin))

while True:
    for i in range(len(pads)):
        touch = pads[i]
        print("%d  " % touch.value, end='')
    for i,fader in enumerate(faders):
        pos = fader.pos()
        if pos is None: 
            pos = 0
        else:
            pos = 100-int(pos*100)
        print(f' SLIDER{i+1}:{pos:0>3}', end='')
    pos = wheel1.pos()
    if pos is None: 
        pos = 0
    else:
        pos = 360-int(pos*360)
    print(f' WHEEL1:{pos:0>3}', end='')
    pos = wheel2.pos()
    if pos is None: 
        pos = 0
    else:
        pos = 360-int(pos*360)
    print(f' WHEEL2:{pos:0>3}', end='')
    print()
    time.sleep(.2)