Last active
September 18, 2019 10:56
-
-
Save bennuttall/6ba25157766d40f97dbbaaf4ca87ace4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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