EloiStree / HelloInput

Collect of information about old project on Input in aim to do a workshop on the topic
0 stars 0 forks source link

Keyword: Electrical Terminal Block & Connection Stip #283

Open EloiStree opened 2 weeks ago

EloiStree commented 2 weeks ago

Terminal Block

Screw Terminal

image https://amzn.to/48SuFHq

Merge

image https://amzn.to/3CqcsVH

Join

image https://amzn.to/48UwrIb



print("Hello Wow Terminal")

import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
import time

# Set up keyboard
keyboard = Keyboard(usb_hid.devices)
cc = ConsumerControl(usb_hid.devices)

pin18 = digitalio.DigitalInOut(board.GP18)
pin18.direction = digitalio.Direction.INPUT
pin18.pull = digitalio.Pull.DOWN

pin19 = digitalio.DigitalInOut(board.GP19)
pin19.direction = digitalio.Direction.INPUT
pin19.pull = digitalio.Pull.DOWN

pin20 = digitalio.DigitalInOut(board.GP20)
pin20.direction = digitalio.Direction.INPUT
pin20.pull = digitalio.Pull.DOWN

pin21 = digitalio.DigitalInOut(board.GP21)
pin21.direction = digitalio.Direction.INPUT
pin21.pull = digitalio.Pull.DOWN

bool_pins_name = {"Pin18","Pin19","Pin20","Pin21"}
pins_read ={}
pins_read["Pin18"] = pin18
pins_read["Pin19"] = pin19
pins_read["Pin20"] = pin20
pins_read["Pin21"] = pin21

key_to_press ={}
key_to_press["Pin18"]= Keycode.ONE
key_to_press["Pin19"]= Keycode.TWO
key_to_press["Pin20"]= Keycode.THREE
key_to_press["Pin21"]= Keycode.TAB

bool_previous_state ={}
for name in bool_pins_name:
    bool_previous_state[name]=False

while True:

    for name in bool_pins_name:
        current_state = pins_read[name].value
        previous_state =bool_previous_state[name]
        bool_previous_state[name]=current_state
        if current_state != previous_state:
            if current_state:
                print("Press Space",name)
                value = key_to_press[name]
                print(f"Type{value}: {value}")
                keyboard.press(key_to_press[name])

            else:
                print("Relase Space",name)
                value = key_to_press[name]
                print(f"Type{value}: {value}")
                keyboard.release(key_to_press[name])

    time.sleep(0.01)