Multithreading 如何删除none并将线程实现到所需的输出 我的目标 在raspberry init self和main变量上设置gpio 此循环获取a和b的状态比较、获取方向、计数和去Bounces 此循环获取a和b的状态比较、获取方向、计数和去Bounces 永远循环以从两个编码器获得连续计数 这个医生解释了我的问题 重置覆盆子上的gpio 启动程序 用于调用循环以启动 删除回溯错误消息
我解决了第一个问题。这是怎么回事 因为有两个打印语句。第一个是内部功能,第二个是外部功能。当函数不返回任何东西时,它不返回任何值 我从循环中删除了打印,并替换了返回语句的位置 范例 打印自我计数器1和打印自我计数器2Multithreading 如何删除none并将线程实现到所需的输出 我的目标 在raspberry init self和main变量上设置gpio 此循环获取a和b的状态比较、获取方向、计数和去Bounces 此循环获取a和b的状态比较、获取方向、计数和去Bounces 永远循环以从两个编码器获得连续计数 这个医生解释了我的问题 重置覆盆子上的gpio 启动程序 用于调用循环以启动 删除回溯错误消息,multithreading,python-2.7,class,raspberry-pi,Multithreading,Python 2.7,Class,Raspberry Pi,我解决了第一个问题。这是怎么回事 因为有两个打印语句。第一个是内部功能,第二个是外部功能。当函数不返回任何东西时,它不返回任何值 我从循环中删除了打印,并替换了返回语句的位置 范例 打印自我计数器1和打印自我计数器2 我想知道是否可以对两个编码器使用相同的while循环您应该真正编辑您的问题,以便python代码上的缩进是有效的语法。 #!/usr/bin/env python import RPi.GPIO as GPIO from time import sleep """ this is
我想知道是否可以对两个编码器使用相同的while循环您应该真正编辑您的问题,以便python代码上的缩进是有效的语法。
#!/usr/bin/env python
import RPi.GPIO as GPIO
from time import sleep
"""
this is writen for the raspberry pi to get an input from two encoder and print a numberical
count. this will use with a telescope and stellarium
this need lot more work but just a beginner still
"""
class EncoderSetup:
def __init__(self, azm_a=27, azm_b=17, lat_a=20, lat_b=21, counter1=0, counter2=0):
self.azm_a = azm_a
self.azm_b = azm_b
self.lat_a = lat_a
self.lat_b = lat_b
self.counter1 = counter1
self.counter2 = counter2
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.azm_a, GPIO.IN)
GPIO.setup(self.azm_b, GPIO.IN)
GPIO.setup(self.lat_a, GPIO.IN)
GPIO.setup(self.lat_b, GPIO.IN)
class Azimuth(EncoderSetup):
def azm_encoder(self):
Last_RoB_Status = GPIO.input(self.azm_b)
while not GPIO.input(self.azm_a): # starts encoder loop
Current_RoB_Status = GPIO.input(self.azm_b)
dtState = GPIO.input(self.azm_a)
if Current_RoB_Status != Last_RoB_Status:
if dtState != Current_RoB_Status:
self.counter1 += 1
else:
self.counter1 -= 1
Last_RoB_Status = Current_RoB_Status # deboucing
# sleep(0.01)
return self.counter1
class Latitude(EncoderSetup):
def lat_encoder(self):
Last_RoC_Status = GPIO.input(self.lat_a)
while not GPIO.input(self.lat_b):
Current_RoC_Status = GPIO.input(self.lat_a)
dtState2 = GPIO.input(self.lat_b)
if Current_RoC_Status != Last_RoC_Status:
if dtState2 != Current_RoC_Status:
self.counter2 += 1
else:
self.counter2 -= 1
Last_RoC_Status = Current_RoC_Status # deboucing
# sleep(0.01)
return self.counter2
def loop():
eset = EncoderSetup()
azm = Azimuth()
lat = Latitude()
while True:
print ('globalCounter1 = ' + str(azm.azm_encoder()) +
' globalCounter2 = ' + str(lat.lat_encoder()))
"""
this is my problem i get a numerical output with none example
globalcounter1 = none globalcounter2 none
globalcounter1 = 0 globalcounter2 none
globalcounter1 = none globalcounter2 0
globalcounter1 = none globalcounter2 none
globalcounter1 = 4 globalcounter2 -1
globalcounter1 = 5 globalcounter2 none
the second problem is i got to turn lat_encoder first before
i get and out from azm_encoder. i think i need to implement threading
or the the same loop for both lat_encoder and azm_encoder
please help me i little lost at this point
"""
def destroy():
GPIO.cleanup()
if __name__ == '__main__':
try:
loop()
except KeyboardInterrupt:
destroy()