使用异步python控制乐高(tm)蓝牙集线器、电机和传感器
bricknil的Python项目详细描述
bricknil[*]提供了连接和编程乐高®的简单方法。 蓝牙集线器(包括Poweredup客运列车60197和货运列车60198以及乐高 Duplo Steam Train10874和Cargo Train10875)在OS X和 Linux系统。这项工作的灵感来自于这个EuroBricks线程和nodejs Powered-Up 图书馆。与乐高提供的官方应用不同,bricknil允许您控制多个 只有一个程序的集线器,让您可以轻松地扩展到编程大型交互系统。
bricknil需要现代python(为3.7设计和测试)并使用异步 建立在Curio异步库之上的事件编程。作为旁白,选择 异步库是相当任意的;并且启用另一个库,如asyncio或trio 应该直截了当。
控制列车电机速度的bricknil程序示例如下:
fromcurioimportsleepfrombricknilimportattach,startfrombricknil.hubimportPoweredUpHubfrombricknil.sensorimportTrainMotor@attach(TrainMotor,name='motor')classTrain(PoweredUpHub):asyncdefrun(self):foriinrange(2):# Repeat this control two timesawaitself.motor.ramp_speed(80,5000)# Ramp speed to 80 over 5 secondsawaitsleep(6)awaitself.motor.ramp_speed(0,1000)# Brake to 0 over 1 secondawaitsleep(2)asyncdefsystem():train=Train('My train')if__name__=='__main__':start(system)
- 免费开源软件:ASL2许可证
- 文档:http://virantha.github.io/bricknil
- 来源:https://github.com/virantha/bricknil
[*] | BrickNil’s name comes from the word “Nil” (නිල්) in Sinhala which means Blue (as in Bluetooth) |
功能
- 支持以下执行器/传感器:
- 内部电机
- 列车电机
- 集线器LED颜色
- 增强视觉传感器(颜色、距离)
- 增强内部倾斜/定向/加速计
- 增压外部电机
- 外部照明
- 轮毂按钮
- 电火花线切割外部电机
- 电火花线切割倾斜和运动传感器
- 完全支持python异步关键字和协程
- 允许使用异步/等待语法进行表示性并发编程
- 当前实现使用david beazley的异步库Curio
- 跨平台
- 使用适用于Mac OS X的Adafruit Bluefruit Bluetoothle库
- 在linux和win10上使用bleak蓝牙库;也在raspberry pi上进行了测试。