#assistive-tech.py

import board, time, neopixel, touchio, adafruit_mpr121
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_debouncer import Button

kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd) # use US keyboard

#UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, TAB
# setup keys work!
keys = [Keycode.W, Keycode.A, Keycode.S, Keycode.D]

i2c = board.I2C()
touch_pad = adafruit_mpr121.MPR121(i2c)
pads =[]
for t_pad in touch_pad:
    pads.append(Button(t_pad, value_when_pressed=True))
strip = neopixel.NeoPixel(board.A1, 30, brightness=0.5)

strip.fill((0, 0, 0))
while True:
    for i in range(len(keys)):
        pads[i].update()
        if pads[i].pressed:
            kbd.press(keys[i])
            if i == 0: # triggering W, flash upper lights
                strip.fill((0, 0, 0))
                strip[4:11] = ((255, 255, 255)) * 7
                strip[28:30] = ((255, 255, 255)) * 2
            elif i == 1: #A
                strip.fill((0, 0, 0))
                strip[11:16] = ((255, 255, 255)) * 5
            elif i == 2: #S
                strip.fill((0, 0, 0))
                strip[16:23] = ((255, 255, 255)) * 7
            elif i == 3: #D
                strip.fill((0, 0, 0))
                strip[23:28] = ((255, 255, 255)) * 5
                strip[0:3] = ((255, 255, 255)) * 3
        if pads[i].released:
            kbd.release(keys[i])





