Python中文
首页
教程
问答
标签
搜索
登录
注册
使用单按键运行python代码
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>目前正在建设的汽油动力钢筋混凝土车控制的树莓派和16届阿达弗瑞伺服控制器皮帽。从一个初学者那里可以很好地进行查询,但是简单的Python命令如何通过一个键来执行呢。E、 g.按住键盘上的“w”键运行pwm.setPWM(0,0,servoMax)”。(以便伺服机构推动油门以向前移动车辆)。以下是当前使用的代码:</p> <pre><code>#!/usr/bin/python from Adafruit_PWM_Servo_Driver import PWM import time pwm = PWM(0x40) servoMin = 150 servoMax = 600 def setServoPulse(channel, pulse): pulseLength = 1000000 pulseLength /= 60 print "%d us per period" % pulseLength pulseLength /= 4096 print "%d us per bit" % pulseLength pulse *= 1000 pulse /= pulseLength pwm.setPWM(channel, 0, pulse) pwm.setPWMFreq(60) While (True): pwm.setPWM(0, 0, servoMin) #throttle servo set to off position -should be default pwm.setPWM(0, 0, servoMAX) #throttle servo set on -to be run by "W" key pwm.setPWM(1, 0, servoMin) #steering servo left -by holding "A" key pwm.setPWM(1, 0, servoMax) #steering servo right -by holding "D" key </code></pre> <p>我假设答案包含If和ElseIf命令,但我真的只想运行一个程序,然后按input()键盘来运行代码。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我正在我的项目中使用相同的伺服帽子,并一直在寻找类似的解决方案。到目前为止,我最好的结果是使用pygame的KEYDOWN事件。<a href="https://www.pygame.org/news" rel="nofollow noreferrer">https://www.pygame.org/news</a></p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
我想从用户inpu创建一个类的实例
1 回答
我想从用户导入值,为此
10 回答
我想从用户那里得到一个整数输入,然后让for循环遍历该数字,然后调用一个函数多次
1 回答
我想从用户那里收到一个列表,并在其中执行一些步骤,然后在步骤完成后将其打印回来,但它没有按照我想要的方式工作
6 回答
我想从用户那里获取输入,并将值传递给(average=dict[x]/6),然后在那里获取resu
8 回答
我想从第一个列表中展示第一个词,然后从第二个列表中展示十个词,以此类推- Python
9 回答
我想从第一个空lin开始解析文本文件
9 回答
我想从简历、简历中提取特定部分
7 回答
我想从给定字典(python)的字符串中删除\u00a9、\u201d和类似的字符。
4 回答
我想从给定的网站Lin下载许多文件扩展名相同的Wget或Python文件
10 回答
我想从网上搜集一些关于抵押贷款的数据
1 回答
我想从网站上删除电子邮件地址
2 回答
我想从网站上读取数据该网站包含可下载的文件,然后我想用python脚本把它发送给oracle如何?
10 回答
我想从网站中提取数据,然后将其显示在我的网页上
1 回答
我想从网页上提取统计数据。
3 回答
我想从网页上解析首都城市,并在用户输入国家时在终端上打印它们
5 回答
我想从色彩图中删除前n个颜色,而不丢失原始颜色数
5 回答
我想从课堂上打印字典里的键
8 回答
我想从费用表中获取学生上次支付的费用,其中学生id=id
10 回答
我想从较低的顺序对多重列表进行排序,但我无法在一行中生成结果
8 回答