我对python还很陌生,正在与firmata一起工作,我正试着和一个arduino一起玩。在
以下是我想要的:
将电位计设置为模拟0
将PyQt计时器设置为更新
电位计位置在
应用程序
在PyQt中设置一个阈值以进行转向
LED亮(模拟输入有1024位
分辨率,所以说800是
阈值)
我正在使用这个firmata库: Link
以下是我遇到问题的代码:
导入系统 从PyQt4导入QtCore,QtGui 来自firmata import*
# Arduino setup
self.a = Arduino('COM3')
self.a.pin_mode(13, firmata.OUTPUT)
# Create timer
self.appTimer = QtCore.QTimer(self)
self.appTimer.start(100)
self.appTimer.event(self.updateAppTimer())
def updateAppTimer(self):
self.analogPosition = self.a.analog_read(self, 0)
self.ui.lblPositionValue.setNum()
我收到错误消息:
Traceback (most recent call last): File "D:\Programming\Eclipse\IO Demo\src\control.py", line 138, in myapp = MainWindow() File "D:\Programming\Eclipse\IO Demo\src\control.py", line 56, in init self.appTimer.event(self.updateAppTimer()) File "D:\Programming\Eclipse\IO Demo\src\control.py", line 60, in updateAppTimer self.analogPosition = self.a.analog_read(self, 0) TypeError: analog_read() takes exactly 2 arguments (3 given)
如果我去掉“self”,我会得到相同的错误消息,但是只给出了1个参数
我不知道python在隐式地做什么?在
Blockquote
在您的代码中,“a”是类实例,因此所有绑定到它的方法都已经将自指针作为第一个参数传递。 欢迎来到python,有一天你会喜欢的:)
在任何一个类中,你都可以调用它。语法是:
自我不需要被超越。我不知道为什么它第一次失败,也不知道为什么self已经被包括在内了。在
相关问题 更多 >
编程相关推荐