변수 mod 2가 0인지 아닌지 확인하여 while
루프의 조건을 앞뒤로 뒤집을 수 있도록 다른 정수에 정수를 추가하기 위해 Raspberry Pi의 단추를 프로그래밍하려고합니다. 나는 본질적으로 변수가 홀수인지 또는 짝수인지를 검사하여 루프를 while
루프로 바꾸려고합니다.어떻게 gpiozero button.when_pressed 함수를 사용하여 정수를 입력하고 출력하는 함수를 사용할 수 있습니까?
나는 gpiozero
라이브러리의 when_pressed
함수를 사용하려하지만 정수를 더하고 출력하는 함수를 호출 할 수없는 것 같습니다.
그래서, 내 코드는 다음과 같습니다
from gpiozero import Button
btn = Button(17) #the button is wired to GPIO pin 17
def addSurf(a):
a = a + 1
return(a)
x = 0
btn.when_pressed = addSurf(x)
while True:
if x == 0:
#do some stuff
else:
#do some other stuff
나는 이것을 실행하려고 내가 TypeError: unsupported operand type(s) for +: 'Button' and 'int'
을받을 이유.
btn.when_pressed
함수를 사용하여 정수를 입력하고 출력하는 함수를 어떻게 사용할 수 있습니까?
또는 while
루프의 두 상태를 단추가 전환하도록하는 다른 [better?] 메서드가 있습니까?