from gpiozero import Button | |
from gpiozero.tools import all_values, any_values | |
class MyButton(Button): | |
def __and__(self, other): | |
return all_values(self, other) | |
def __or__(self, other): | |
return any_values(self, other) | |
led = LED(2) | |
btn1 = MyButton(3) | |
btn2 = MyButton(4) | |
led.source = btn1 & btn2 | |
print(led.value) # 0 | |
btn1.pin.drive_low() | |
print(led.value) # 0 | |
btn2.pin.drive_low() | |
print(led.value) # 1 | |
btn1.pin.drive_high() | |
btn2.pin.drive_high() | |
led.source = btn1 | btn2 | |
print(led.value) # 0 | |
btn1.pin.drive_low() | |
print(led.value) # 1 | |
btn2.pin.drive_low() | |
print(led.value) # 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment