Adafruit nrf52840循环程序



我正在使用Adafruit"BLE HID键盘按钮";教程:我想使用箭头在具有辅助功能的窗口中导航->iPad上的访问控制,但一旦我连接到蓝牙,为五个按钮定义的字符就会在我打开的任何文本字段(浏览器、笔记应用程序等(中以重复顺序显示。我如何停止这种重复顺序,以便只在按下五个按钮中的任何一个时使用五个按钮?我在脚本中没有看到任何循环(我只是摆弄编程(

#This example acts as a BLE HID keyboard to peer devices.
#Attach five buttons with pullup resistors to Feather nRF52840
#each button will send a configurable keycode to mobile device or computer
import time
import board
from digitalio import DigitalInOut, Direction
import adafruit_ble
from adafruit_ble.advertising import Advertisement
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.standard.hid import HIDService
from adafruit_ble.services.standard.device_info import DeviceInfoService
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
button_1 = DigitalInOut(board.D11)
button_2 = DigitalInOut(board.D10)
button_3 = DigitalInOut(board.D9)
button_4 = DigitalInOut(board.D6)
button_5 = DigitalInOut(board.D5)
button_1.direction = Direction.INPUT
button_2.direction = Direction.INPUT
button_3.direction = Direction.INPUT
button_4.direction = Direction.INPUT
button_5.direction = Direction.INPUT
hid = HIDService()
device_info = DeviceInfoService(software_revision=adafruit_ble.__version__,
manufacturer="Adafruit Industries")
advertisement = ProvideServicesAdvertisement(hid)
advertisement.appearance = 961
scan_response = Advertisement()
scan_response.complete_name = "CircuitPython HID"
ble = adafruit_ble.BLERadio()
if not ble.connected:
print("advertising")
ble.start_advertising(advertisement, scan_response)
else:
print("already connected")
print(ble.connections)
k = Keyboard(hid.devices)
kl = KeyboardLayoutUS(k)
while True:
while not ble.connected:
pass
print("Start typing:")
while ble.connected:
if not button_1.value:  # pull up logic means button low when pressed
k.send(Keycode.DOWN_ARROW)
time.sleep(0.4)
if not button_2.value:
k.send(Keycode.LEFT_ARROW)
time.sleep(0.4)
if not button_3.value:
k.send(Keycode.UP_ARROW)
time.sleep(0.4)
if not button_4.value:
k.send(Keycode.RIGHT_ARROW)
time.sleep(0.4)
if not button_5.value:
k.send(Keycode.ENTER)
time.sleep(0.4)
ble.start_advertising(advertisement)

USB HID键盘要求您释放按下的任何键,否则主机(通常(将执行";类型化的";重复按下它看到的最后一个键。

尝试在每次按键后调用release_all((。更多信息在源代码中:

https://circuitpython.readthedocs.io/projects/hid/en/latest/_modules/adafruit_hid/keyboard.html#Keyboard.release_all

Aja,

感谢您的回复。问题是序列在没有按下任何键的情况下开始。最后(感谢Dave(将每个按钮的pull属性设置为digitalio。拉UP成功了。不过,我会尝试一下你的解决方案,因为我认为它在我的项目后期肯定会有用。

问候

Philippe

相关内容

  • 没有找到相关文章

最新更新