我的我的Raspberry Pi的python程序出了問題。我想從一個類的def中創建一個線程。它顯示了以下錯誤,當我嘗試運行代碼:Python線程錯誤,任何人都有解決方案?
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: check_keys() takes no arguments (1 given)
這裏是我的代碼:
import thread
import RPi.GPIO as GPIO
import threading
ROW = []
COL = []
chars = []
GPIO.setmode(GPIO.BOARD)
MATRIX = [ ['1','2','3'],
['4','5','6'],
['7','8','9'],
['*','0','#'] ]
class keypad():
def __init__(self, gpio_col, gpio_row):
COL = gpio_col
ROW = gpio_row
for j in range(3):
GPIO.setup(COL[j], GPIO.OUT)
GPIO.output(COL[j], 1)
for i in range(4):
GPIO.setup(ROW[i], GPIO.IN, pull_up_down = GPIO.PUD_UP)
def check_keys():
try:
while(True):
for j in range(3):
GPIO.output(COL[j],0)
for i in range(4):
if GPIO.input(ROW[i]) == 0:
chars.append(MATRIX[i][j])
print(MATRIX[i][j])
while(GPIO.input(ROW[i]) == 0):
pass
GPIO.output(COL[j],1)
except KeyboardInterrupt:
GPIO.cleanup()
def get_chars():
return chars
和:
import socket
import time
import pylcdlib
import keypadlib
from threading import Thread
#init keypad
ROW = [23,21,19,18]
COL = [13, 15, 16]
keypad = keypadlib.keypad(COL, ROW)
thread = Thread(target = keypad.check_keys)
任何人都得到一個解決方案嗎?
在此先感謝
請修正您的示例代碼的語法('IndentationError:expected an indendum block')。 –
我已刷新代碼 – JuNijland
現在看起來好多了:) –