I can't seem to find a solution of doing this using gpiozero. I've done it using rpi.gpio with add_event_detect and call back to change state but I was under the impression gpiozero is much simpler.
This link https://projects.raspberrypi.org/en/projects/physical-computing/9 basically says a switch would turn the led on with a pressed and release then turn is off with another pressed and release but doesn't actually show how to do this.
from gpio import LEDBoard, Button
button = Button(5, pull_up=True, bounce_time=200)
leds = LEDBoard(26, 19, 13, 6)
def on():
leds.on()
print('On...')
def off():
leds.off()
print('off...')
button.when_pressed = on
button.when_released = off
It doesn't even turn off when released. Is that due to the pull_up = True? I thought this code would turn it on when pressed and off when released but it just turns on and stays on.
TIA!