Exemplo n.º 1
0
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
pix = cpx.pixels
pix.brightness = 0.4
while True:
    x, y, z = cpx.acceleration
    for i in range(10):
        #print(int(x),int(y),int(z))
        pix[i] = (abs(int(x)) * 10 % 255, abs(int(y)) * 10 % 255,
                  abs(int(z)) * 10 % 255)
    if cpx.switch:
        continue

    if x > 3:
        kbd.press(Keycode.LEFT_ARROW)
        sleep(0.2)
        kbd.release(Keycode.LEFT_ARROW)

    if x < -3:
        kbd.press(Keycode.RIGHT_ARROW)
        sleep(0.2)
        kbd.release(Keycode.RIGHT_ARROW)
    if y > 3:
        kbd.press(Keycode.UP_ARROW)
        print("up")
        #sleep(0.2)
        #kbd.release(Keycode.UP_ARROW)
    if y < -4:
        kbd.release(Keycode.UP_ARROW)
        kbd.press(Keycode.DOWN_ARROW)
print("Waiting for button presses")

while True:
    # check each button
    # when pressed, the LED will light up,
    # when released, the keycode or string will be sent
    # this prevents rapid-fire repeats!
    for button in buttons:
        if button.value:  # pressed?
            i = buttons.index(button)
            print("Button #%d Pressed" % i)

            # turn on the LED
            led.value = True

            while button.value:
                pass  # wait for it to be released!
            # type the keycode or string
            k = buttonkeys[i]  # get the corresp. keycode/str
            if isinstance(k, str):
                layout.write(k)
            else:
                kbd.press(controlkey, k)  # press...
                kbd.release_all()  # release!

            # turn off the LED
            led.value = False

    time.sleep(0.01)
Exemplo n.º 3
0
        led2.value = False
        led3.value = False
        led4.value = False
        led5.value = False
        led6.value = False
        led7.value = False
        led8.value = False
        led9.value = False
        led10.value = False
        led11.value = False
        led12.value = True
    else:
        pass

    if not btn1.value:
        keyboard.press(key_Ctrl, key_Keypad1)
        time.sleep(0.1)
        keyboard.release(key_Ctrl, key_Keypad1)
        selectedInput = 1
    elif not btn2.value:
        keyboard.press(key_Ctrl, key_Keypad2)
        time.sleep(0.1)
        keyboard.release(key_Ctrl, key_Keypad2)
        selectedInput = 2
    elif not btn3.value:
        keyboard.press(key_Ctrl, key_Keypad3)
        time.sleep(0.1)
        keyboard.release(key_Ctrl, key_Keypad3)
        selectedInput = 3
    elif not btn4.value:
        keyboard.press(key_Ctrl, key_Keypad4)
Exemplo n.º 4
0
def slow_write(string):  # Typing should not be too fast for
    for c in string:  # the computer to be able to accept
        layout.write(c)
        time.sleep(0.2)  # use 1/5 second pause between characters


while True:
    if switch.value:  # If the slide switch is off, don't log
        continue

    # Turn on the LED to show we're logging
    led.value = True
    temp = thermistor.temperature  # In Celsius
    # if you want Fahrenheit, uncomment the line below
    # temp = temp * 9 / 5 + 32
    # Format data into value 'obj_output'
    obj_output = "{},{},{}".format(time.time(), light.value, temp)
    slow_write(obj_output + "\n")  # print to csv file

    kbd.press(Keycode.DOWN_ARROW)  # Code to go to next row
    time.sleep(0.01)
    kbd.release_all()
    for _ in range(3):
        time.sleep(0.015)
        kbd.release_all()
        time.sleep(0.025)  # Wait a bit more for Google Sheets

    led.value = False
    # Change 0.1 to whatever time you need between readings
    time.sleep(1.0)
Exemplo n.º 5
0
initial_timeout = 0.02
letter_timeout = 0.2
timeout = initial_timeout

while True:
    # Check each pin
    for key_pin in key_pin_array:
        i = key_pin_array.index(key_pin)
        key = keys_pressed[i]  # Get the corresponding Keycode
        if not key_state_array[key] and not key_pin.value:  # Is it grounded?
            # Register key as pressed
            key_state_array[key] = True

        if key_state_array[key] and key_pin.value:
            # Register key as unpressed
            key_state_array[key] = False

    # For each of the keys, if it's pressed, then actually press the key
    for key, value in key_state_array.items():
        if value:
            keyboard.press(key)
            if key != Keycode.CONTROL:
                timeout = letter_timeout

    # Release all keys
    keyboard.release_all()

    time.sleep(timeout)
    timeout = initial_timeout
Exemplo n.º 6
0
last_press = time.monotonic()
snore_count = -1
while True:
    pressed = set(trellis.pressed_keys)
    now = time.monotonic()
    sleep_time = now - last_press
    sleeping = sleep_time > TIMEOUT
    for down in pressed - current_press:
        if down in keymap and not sleeping:
            print("down", down)
            # Lower the brightness so that we don't draw too much current when we turn all of
            # the LEDs on.
            trellis.pixels.brightness = 0.2
            trellis.pixels.fill(keymap[down][0])
            if keymap[down][1] == KEY:
                kbd.press(*keymap[down][2])
            else:
                cc.send(keymap[down][2])
            # else if the entry starts with 'l' for layout.write
        last_press = now
    for up in current_press - pressed:
        if up in keymap:
            print("up", up)
            if keymap[up][1] == KEY:
                kbd.release(*keymap[up][2])

    # Reset the LEDs when there was something previously pressed (current_press) but nothing now
    # (pressed).
    if not pressed and current_press:
        trellis.pixels.brightness = 1
        trellis.pixels.fill((0, 0, 0))
Exemplo n.º 7
0
        if mode_counter > (len(keys_pressed) - 1):
            mode_counter = 0
    print("mode counter: %d" % mode_counter)

    # Check each pin
    for key_pin in key_pin_array:
        if not key_pin.value:  # Is it grounded?
            i = key_pin_array.index(key_pin)
            print("Pin #%d is grounded." % i)

            # Turn on the red LED
            led.value = True

            while not key_pin.value:
                pass  # Wait for it to be ungrounded!
            # "Type" the Keycode or string
            print(i)
            key = keys_pressed[mode_counter][i]
            print(key)
            keyboard.press(key)  # "Press"...
            keyboard.release_all()  # ..."Release"!

            # Turn off the red LED
            led.value = False

    pixels.fill(mode_color[mode_counter])
    pixels.show()

    time.sleep(0.1)
Exemplo n.º 8
0
 mode = ''
 for num in range(len(keys) - 1):
     if keys[num] == '':
         keys.pop(num)
 for i in range(3):
     if keys[i] == '#clicking':
         mode = 'click'
     elif keys[i] == '#typing':
         print(keys)
         for string in keys:
             strsplit = string.split(' ')
             if strsplit[0] == 'type':
                 typestring = strsplit[1].upper()
                 for key in typestring:
                     try:
                         keyboard.press(keycodes[key])
                         sleep(0.05)
                         keyboard.release(keycodes[key])
                     except:
                         print('Unknown Keycode')
             elif strsplit[0] == 'delay':
                 sleep(int(strsplit[1]) * 0.1)
             elif strsplit[0] == 'press':
                 keyboard.press(keycodes[strsplit[1]])
             elif strsplit[0] == 'release':
                 keyboard.release(keycodes[strsplit[1]])
             elif strsplit[0] == '#':
                 None
             else:
                 for key in strsplit:
                     if mode == 'click':
Exemplo n.º 9
0
"""
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from time import sleep

kbd = Keyboard()
layout = KeyboardLayoutUS(kbd)
trigger = 0
mode = 0
while True:
    mode = cpx.switch

    if cpx.button_a:
        trigger = 1

    if cpx.button_b:
        trigger = 0

    if trigger == 1:
        if mode == False:
            kbd.press(Keycode.CONTROL, Keycode.V)
            kbd.release(Keycode.CONTROL, Keycode.V)
            kbd.press(Keycode.RETURN)
            kbd.release(Keycode.RETURN)
        if mode == True:
            kbd.press(Keycode.CONTROL, Keycode.V)
            kbd.release(Keycode.CONTROL, Keycode.V)
    sleep(0.01)
led = digitalio.DigitalInOut(board.D13)
led.switch_to_output()

print("Waiting for button presses")

while True:
    # check each button
    for button in buttons:
        if not button.value:  # pressed?
            i = buttons.index(button)
            leds[i].value = True

            print("Button #%d Pressed" % i)

            # turn on the LED
            led.value = True

            while not button.value:
                pass  # wait for it to be released!
            # type the keycode!
            k = buttonkeys[i]  # get the corresp. keycode
            kbd.press(controlkey, k)
            kbd.release_all()

            # turn off the LED
            led.value = False
            leds[i].value = False

    time.sleep(0.01)
Exemplo n.º 11
0
"""
pin = [board.GP8, board.GP7, board.GP9, board.GP4]
key = [Keycode.ONE, Keycode.TWO, Keycode.GRAVE_ACCENT, Keycode.ESCAPE]
"""
all_key = list(map(lambda x: set_button(x), pin))
last_value = list(map(lambda x: x.value, all_key))
"""
import time
loop_test = 10000
start = time.time()
x = 0
while x < loop_test: #second test
    x = x + 1
    for i, button in enumerate(all_key):
        if last_value[i] != button.value:
            last_value[i] = button.value
            if not button.value:
                usb_keyboard.press(key[i])
            else:
                usb_keyboard.release(key[i])
print("Loop frequency : {}".format(str(loop_test / (time.time() - start))))
"""
while True:
    for i, button in enumerate(all_key):
        if last_value[i] != button.value:
            last_value[i] = button.value
            if button.value:
                usb_keyboard.release(key[i])
            else:
                usb_keyboard.press(key[i])
Exemplo n.º 12
0
last_press = time.monotonic()
snore_count = -1
while True:
    pressed = set(trellis.pressed_keys)
    now = time.monotonic()
    sleep_time = now - last_press
    sleeping = sleep_time > TIMEOUT
    for down in pressed - current_press:
        if down in keymap and not sleeping:
            print("down", down)
            # Lower the brightness so that we don't draw too much current when we turn all of
            # the LEDs on.
            trellis.pixels.brightness = 0.2
            trellis.pixels.fill(keymap[down][0])
            if keymap[down][1] == KEY:
                kbd.press(*keymap[down][2]) if type(keymap[down][2]) == tuple else kbd.press(keymap[down][2])
            else:
                cc.send(keymap[down][2])
            # else if the entry starts with 'l' for layout.write
        last_press = now
    for up in current_press - pressed:
        if up in keymap:
            print("up", up)
            if keymap[up][1] == KEY:
                if type(keymap[down][2]) == tuple:
                    kbd.release(*keymap[down][2])
                else:
                    kbd.release(keymap[down][2])

    # Reset the LEDs when there was something previously pressed (current_press) but nothing now
    # (pressed).
Exemplo n.º 13
0
x_axis = analogio.AnalogIn(board.A0)
y_axis = analogio.AnalogIn(board.A1)


def get_voltage(pin):
    return (pin.value * 3.3) / 65535  # ADC 12-bits [0 - 3.3]


while True:
    x = get_voltage(x_axis)
    y = get_voltage(y_axis)
    #print(f"x={x:.4f} | y={y:.4f}")

    if x < 0.3:
        keyboard.press(Keycode.LEFT_ARROW)
        time.sleep(0.1)
        keyboard.release(Keycode.LEFT_ARROW)

    elif x > 3.0:
        keyboard.press(Keycode.RIGHT_ARROW)
        time.sleep(0.1)
        keyboard.release(Keycode.RIGHT_ARROW)

    elif y < 0.3:
        keyboard.press(Keycode.DOWN_ARROW)
        time.sleep(0.1)
        keyboard.release(Keycode.DOWN_ARROW)

    elif y > 3.0:
        keyboard.press(Keycode.UP_ARROW)
Exemplo n.º 14
0
time.sleep(0.006)
clk.value = False
time.sleep(0.006)
clk.direction = Direction.INPUT

kbd = Keyboard()
pulses = pulseio.PulseIn(board.D3, maxlen=12, idle_state=True)

pulses.resume()
while True:
    if not clk.value:
        time.sleep(0.005)
        pulses.pause()
        a = tuple([int(pulses[pulse] / 80) for pulse in range(1, len(pulses))])
        if not a:
            pass
        elif a in mapping.modifiers:
            #if we pressed a modifer, well press it
            kbd.press(mapping.modifiers[a])
        elif a[0] in (17, 24) and a[2:] in mapping.modifiers:
            #the first part of the tuple is always 17 or 24 for releases
            #so if we released a modifer, release it
            kbd.release(mapping.modifiers[a[2:]])
        elif a in mapping.keys:
            kbd.press(mapping.keys[a])
            kbd.release(mapping.keys[a])
        else:
            print(a)
        pulses.clear()
        pulses.resume()
Exemplo n.º 15
0
        #       if i ==0:
        #           continue
        #       if i>6:
        #           break
        #       txt += row[0]
        valid = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm .0987654321"
        with open('tweet.csv', 'r', encoding="utf8") as f:
            results = []
            for i, line in enumerate(f):
                if i == 0:
                    continue
                if i > 6:
                    break
                words = line.split(',')
                txt += words[0][:-1]

            for i in txt:
                if i in valid:
                    txt2 += i
            # print(results)
            try:
                layout.write(txt2)
                kbd.press(Keycode.RETURN)
                kbd.release(Keycode.RETURN)
            except:
                kbd.press(Keycode.RETURN)
                kbd.release(Keycode.RETURN)

    if cp.button_b:
        kbd.press(Keycode.GRAVE_ACCENT)
        kbd.release(Keycode.GRAVE_ACCENT)
Exemplo n.º 16
0
import board
import digitalio
import time
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

led = digitalio.DigitalInOut(board.A3)
led.direction = digitalio.Direction.OUTPUT

switch = digitalio.DigitalInOut(board.D2)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP

time.sleep(1)  # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard()
keyboard_layout = KeyboardLayoutUS(keyboard)

led.value = True

while True:
    time.sleep(0.5)
    if not switch.value:
        led.value = False
        keyboard.press(Keycode.F5)
        keyboard.release_all()
        print("Switch is on!")
        time.sleep(1)
    else:
        led.value = True
        print("Switch is off!")
Exemplo n.º 17
0
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

hid = HIDService()
advertisement = ProvideServicesAdvertisement(hid)
advertisement.complete_name = 'CIRCUITPY KEYBOARD'
advertisement.appearance = 961
ble = adafruit_ble.BLERadio()
if ble.connected:
    for c in ble.connections:
        c.disconnect()
ble.start_advertising(advertisement)
advertising = True
ble_keyboard = Keyboard(hid.devices)

button = digitalio.DigitalInOut(board.USR_BTN)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

last_value = button.value

while True:
    if last_value != button.value:
        last_value = button.value
        print('Button is ' + ('released' if button.value else 'pressed'))
        if ble.connected:
            if not button.value:
                ble_keyboard.press(Keycode.A)
            else:
                ble_keyboard.release(Keycode.A)
Exemplo n.º 18
0
            mouse.move(0, 0, 1)
            time.sleep(0.01)
    elif diff < 0:
        for i in range(-diff):
            mouse.move(0, 0, -1)
            time.sleep(0.01)


while True:
    diff = last_encoder_val - encoder.position  # encoder clicks since last read
    last_encoder_val = encoder.position
    ring_pos = (ring_pos + diff) % len(ring)  # position on LED ring
    hue = colorwheel(encoder.position * 4 % 255)  # fun hue change based on pos

    if not button.value:  # button pressed
        keyboard.press(Keycode.LEFT_SHIFT)
        scroll(diff)
        keyboard.release(Keycode.LEFT_SHIFT)
        for i in range(len(ring)):  # spin the rainbow while held
            pixel_index = (i * 256 // len(ring)) + rainbow_pos
            ring[i] = colorwheel(pixel_index & 255)
            ring.show()
            rainbow_pos = (rainbow_pos + 1) % 256
    else:
        scroll(diff)

        ring.fill([int(i / 4) for i in hue])  # make it 1/4 dimmer
        ring[ring_pos] = (255, 255, 255)
        ring[(ring_pos - 1) % len(ring)] = (67, 67, 67)
        ring[(ring_pos + 1) % len(ring)] = (67, 67, 67)
        ring.show()
Exemplo n.º 19
0
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.direction = digitalio.Direction.OUTPUT

print("Waiting for key pin...")

while True:
    # Check each pin
    for key_pin in key_pin_array:
        if not key_pin.value:  # Is it grounded?
            i = key_pin_array.index(key_pin)
            print("Pin #%d is grounded." % i)

            # Turn on the red LED
            led.value = True

            while not key_pin.value:
                pass  # Wait for it to be ungrounded!
            # "Type" the Keycode or string
            key = keys_pressed[i]  # Get the corresponding Keycode or string
            if isinstance(key, str):  # If it's a string...
                keyboard_layout.write(key)  # ...Print the string
            else:  # If it's not a string...
                keyboard.press(control_key, key)  # "Press"...
                keyboard.release_all()  # ..."Release"!

            # Turn off the red LED
            led.value = False

    time.sleep(0.01)
Exemplo n.º 20
0
# https://hridaybarot.home.blog/2021/01/31/using-raspberry-pi-pico-has-hid-device-to-control-mouse-and-keyboard/
#
# Download or clone this repo:
#   https://github.com/adafruit/Adafruit_CircuitPython_HID
#
# In there, there is a folder called adafruit_hid ,
# copy that folder to the Pico where CircuitPython is already installed.

import time
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

key_A = Keycode.A
key_Shift = Keycode.SHIFT
keyboard = Keyboard(usb_hid.devices)

time.sleep(2)
print("Sending keys now...")

keyboard.press(key_Shift, key_A)
keyboard.release(key_Shift, key_A)
Exemplo n.º 21
0
    # else:
    #     if not button2.value:
    #         #print("Button 2 pressed!")
    #         # channel.write(["", "bproc", "./test.sh"])
    #         channel.write(["dbput", "dbput", "TESTING", "FROMPORTAL"])
    #         channel.write(["dbput", "dbput", "TESTING", "TIME:" + str(time.time())])
    #         button2_pressed = True

    if mcp is not None:
        for i in range(pin_count):
            value = pins[i].value
            if value != pin_states[i]:
                # print("Pin " + str(i) + " is " + str(value))
                pin_states[i] = value
                if not value:
                    kbd.press(*pin_keys[i])
                else:
                    kbd.release(*pin_keys[i])

    point = touch.touch_point
    if point:
        # Touch point needs to be rotated, flipped vertically, and halved
        point = (point[1] // 2), ((480 - point[0]) // 2)
        for button in buttons:
            if button.contains(point):
                button.selected = True
            elif button.selected:
                button.selected = False
        had_point = True
    elif had_point:
        for button in buttons:
    # has the state changed?
    if touching and not touch2.value:
        # we just stopped touching it
        # read how long it was touched 
        print("touched for", i)
        if i < threshold:
            letter_buffer.append('.')
        else:
            letter_buffer.append('-')
        touching = False
        i = 0

    if not touching and touch2.value:
        # we just started touching it
        # read how long we were silent
        print("absent for", i)
        touching = True
        i = 0

    if not touching and not touch2.value:
        if i > threshold and letter_buffer:
            letter = "".join(letter_buffer)
            letter_buffer = []
            print("read", letter)
            key = morse_code_dict.get(letter)
            if key:
                kbd.press(key)
                kbd.release_all()

    led.value = touch2.value
Exemplo n.º 23
0
btn2.direction = digitalio.Direction.INPUT

keyboard = Keyboard(usb_hid.devices)

while True:
    print(btn1.value, btn2.value)

    keys = [
        (btn1, Keycode.A),
        (btn2, Keycode.B)
    ]
    key_press_flags = [
        False,
        False,
    ]

    for i, (btn, keycode) in enumerate(keys):
        if not btn.value:  #Press
            keyboard.press(keycode)
            key_press_flags[i] = True
            led.value = True
    
    time.sleep(0.5)

    for i, (btn, keycode) in enumerate(keys):
        if key_press_flags[i]:
            keyboard.release(keycode)
    
    led.value = False
    time.sleep(0.1)
                                    # get actions for this icon from config object
                                    _cur_actions = touch_deck_config["layers"][
                                        current_layer]["shortcuts"][index][
                                            "actions"]

                                    # tuple means it's a single action
                                    if isinstance(_cur_actions, tuple):
                                        # put it in a list by itself
                                        _cur_actions = [_cur_actions]

                                    # loop over the actions
                                    for _action in _cur_actions:
                                        # HID keyboard keys
                                        if _action[0] == KEY:
                                            kbd.press(*_action[1])
                                            kbd.release(*_action[1])

                                        # String to write from layout
                                        elif _action[0] == STRING:
                                            kbd_layout.write(_action[1])

                                        # Consumer control code
                                        elif _action[0] == MEDIA:
                                            cc.send(_action[1])

                                        # Key press
                                        elif _action[0] == KEY_PRESS:
                                            kbd.press(*_action[1])

                                        # Key release
Exemplo n.º 25
0
zoom_mute = digitalio.DigitalInOut(board.GP10 )

zoom_mute.switch_to_input(pull=digitalio.Pull.DOWN)
teams_mute.switch_to_input(pull=digitalio.Pull.DOWN)

kbd = Keyboard(usb_hid.devices)


sleep(1)
zoom_mic_status = False
teams_mic_status = False

while True: 
    if zoom_mute.value == True:
        if zoom_mic_status == False:
            kbd.press(Keycode.ALT)
            kbd.press(Keycode.A)
            kbd.release_all()
            zoom_mic_status = True
    else:
        if zoom_mic_status == True:
            kbd.press(Keycode.ALT)
            kbd.press(Keycode.A)
            kbd.release_all()
            zoom_mic_status = False

    if teams_mute.value == True:
        if teams_mic_status == False:
            kbd.press(Keycode.CONTROL)
            kbd.press(Keycode.SHIFT)
            kbd.press(Keycode.M)
Exemplo n.º 26
0
    cap_touches[0] = t0_count > 2
    cap_touches[1] = touches[1].raw_value > 3000
    cap_touches[2] = touches[2].raw_value > 3000
    cap_touches[3] = touches[3].raw_value > 3000
    return cap_touches

while True:
    caps = read_caps()
    print(caps)
    # light up the matching LED
    for i,c in enumerate(caps):
        leds[i].value = c
    if caps[0]:
        if ENABLE_KEYBOARD:
            # Zoom
            kbd.press(Keycode.ALT, Keycode.V)
            kbd.release(Keycode.V)
            time.sleep(0.25)
            kbd.press(Keycode.A)
            kbd.release_all()
    if caps[1]:
        if ENABLE_KEYBOARD:
            # Teams
            # Note that video toggle doesn't work in the web app
            kbd.press(Keycode.CONTROL, Keycode.SHIFT, Keycode.M)
            kbd.release(Keycode.M)
            time.sleep(0.5)
            kbd.press(Keycode.O)
            kbd.release_all()
    if caps[2]:
        if ENABLE_KEYBOARD:
import time
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import board
import digitalio

kbd = Keyboard()

# define buttons. these can be any physical switches/buttons, but the values
# here work out-of-the-box with a CircuitPlayground Express' A and B buttons.
swap = digitalio.DigitalInOut(board.D4)
swap.direction = digitalio.Direction.INPUT
swap.pull = digitalio.Pull.DOWN

search = digitalio.DigitalInOut(board.D5)
search.direction = digitalio.Direction.INPUT
search.pull = digitalio.Pull.DOWN

while True:
    # press ALT+TAB to swap windows
    if swap.value:
        kbd.press(Keycode.ALT, Keycode.TAB)
        kbd.release_all()

    # press CTRL+K, which in a web browser will open the search dialog
    elif search.value:
        kbd.press(Keycode.CONTROL, Keycode.K)
        kbd.release_all()

    time.sleep(0.1)
Exemplo n.º 28
0
######################### MAIN LOOP ##############################

i = 0
while True:
    # spin internal LED around!
    dot[0] = wheel(i)
    dot.show()

    # set analog output to 0-3.3V (0-65535 in increments)
    aout.value = i * 256

    # once every 256 ticks, so it doesnt rush by!
    if i == 0:
        # Read analog voltage on A1
        print("A1: %0.2f" % getVoltage(analog1in))
        # Print the temperature
        print("Temp: %0.1f" % microcontroller.cpu.temperature)

    # use A2 as capacitive touch to turn on internal LED
    if touch2.value:
        print("A2 touched!")
        # optional! uncomment below & save to have it sent a keypress
        kbd.press(Keycode.A)
        kbd.release_all()
        time.sleep(1)

    led.value = touch2.value

    i = (i + 1) % 256  # run from 0 to 255
    ([255, 2, 151, 104],(Keycode.SIX,)),
    ([255, 2, 231, 24], (Keycode.SEVEN,)),
    ([255, 2, 103, 152],(Keycode.EIGHT,)),
    ([255, 2, 167, 88], (Keycode.NINE,)),

)

print("Ready for NEC remote input!")

while True:
    led[0] = (0, 0, 0)   # LED off
    pulses = decoder.read_pulses(pulsein)
    #print("\tHeard", len(pulses), "Pulses:", pulses)
    try:
        code = decoder.decode_bits(pulses, debug=False)
        print("Decoded:", code)
        # Reads 4-byte code transmitted by NEC remotes and
        # sends a matching key command
        for pairs in infrared_to_key:
            if pairs[0] == code:
                led[0] = (0, 100, 0)                   # flash green
                print("Matched IR code to keypresses: ", pairs[1])
                keyboard.press(*pairs[1])
                keyboard.release_all()
    except adafruit_irremote.IRNECRepeatException:     # unusual short code!
        print("NEC repeat!")
    except adafruit_irremote.IRDecodeException as e:   # failed to decode
        led[0] = (100, 0, 0)                           # flash red
        print("Failed to decode: ", e.args)
    print("----------------------------")
Exemplo n.º 30
0
    if (left_right < -0.25):
        left_pressed = True
    elif (left_right > 0.25):
        right_pressed = True

    if (up_down < -0.25):
        down_pressed = True
    elif (up_down > 0.25):
        up_pressed = True

    # For each type of key, we press it down,
    # release it, or leave it in its current state.
    #
    if not up_state and up_pressed:
        if player == 1:
            keyboard.press(Keycode.UP_ARROW)
        else:
            keyboard.press(Keycode.K)
            keyboard.press(Keycode.W)
        up_state = True
    elif up_state and not up_pressed:
        if player == 1:
            keyboard.release(Keycode.UP_ARROW)
        else:
            keyboard.release(Keycode.K)
            keyboard.release(Keycode.W)
        up_state = False

    if not down_state and down_pressed:
        if player == 1:
            keyboard.press(Keycode.DOWN_ARROW)