帮助,我已经制作了一个部分工作的计数器。我有2个输入,当任何一个输入被触发时,我希望计数器增加1。从我已经制作的代码我只能使计数器计数当我有一个输入一旦我加入并触发第二个输入我得到一个错误说"无效的文字为int()与基数10"这是我的代码,请帮助。
from time import sleep
import RPi.GPIO as GPIO
import os
GPIO.setmode(GPIO.BOARD)
button1=40
button2=11
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(button2,GPIO.IN,pull_up_down=GPIO.PUD_UP)
while(1):
if GPIO.input(button1)==0:
f = open("counter1.txt","r+")
counter = int(f.readline())
counter += 1
f.seek(0)
f.write(str(counter))
f.close()
print (counter)
sleep(1)
if GPIO.input(button2)==0:
f = open("counter2.txt","r+")
counter = int(f.readline())
counter += 1
f.seek(0)
f.write(str(counter))
f.close()
print (counter)
sleep(1)
else:
counter = 0
f = open("counter.txt","w+")
f.write(str(counter))
f.close()
print (counter)