Last active
August 17, 2024 18:02
-
-
Save nucklearproject/68bccd857cb436f0a5c6363214487770 to your computer and use it in GitHub Desktop.
circuitpython TTP229 connect to raspbery pico
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import board | |
import digitalio | |
import time | |
# Configurar los pines | |
sdo_pin = digitalio.DigitalInOut(board.GP19) | |
sdo_pin.direction = digitalio.Direction.INPUT | |
sdo_pin.pull = digitalio.Pull.UP | |
scl_pin = digitalio.DigitalInOut(board.GP18) | |
scl_pin.direction = digitalio.Direction.OUTPUT | |
scl_pin.value = True | |
def read_ttp229(): | |
key_value = 0 | |
for i in range(16): | |
scl_pin.value = False | |
time.sleep(0.00001) # 10 microsegundos de delay | |
key_value |= (not sdo_pin.value) << i | |
scl_pin.value = True | |
time.sleep(0.00001) # 10 microsegundos de delay | |
return key_value | |
# Bucle principal | |
while True: | |
key_value = read_ttp229() | |
for i in range(16): | |
if key_value & (1 << i): | |
print(f"Tecla {i+1} presionada") | |
time.sleep(0.1) |
Author
nucklearproject
commented
Aug 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment