Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active September 18, 2019 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennuttall/6ba25157766d40f97dbbaaf4ca87ace4 to your computer and use it in GitHub Desktop.
Save bennuttall/6ba25157766d40f97dbbaaf4ca87ace4 to your computer and use it in GitHub Desktop.
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