Skip to content

Instantly share code, notes, and snippets.

@devjourney
Last active December 8, 2019 04:36
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 devjourney/744535147a74cc9f14256c7955f4d4b1 to your computer and use it in GitHub Desktop.
Save devjourney/744535147a74cc9f14256c7955f4d4b1 to your computer and use it in GitHub Desktop.
Python script for Raspberry Pi to alternate flashing of two LEDs with two buttons for modifying the duration of the delays between alternations.
from gpiozero import LED, Button
from time import sleep
minimum = 0.0625
maximum = 1.00
increment = 0.0625
delay = minimum
def set_delay(offset):
global delay, minimum, maximum
newdelay = delay + offset
if newdelay >= minimum and newdelay <= maximum:
print("set " + str(newdelay))
delay = newdelay
else:
print("not set " + str(newdelay))
def increase_delay():
global increment
set_delay(increment)
def decrease_delay():
global increment
set_delay(-increment)
greenled = LED("GPIO04")
redled = LED("GPIO18")
upbutton = Button("GPIO26")
downbutton = Button("GPIO20")
upbutton.when_released = increase_delay
downbutton.when_released = decrease_delay
while True:
greenled.on()
redled.off()
sleep(delay)
greenled.off()
redled.on()
sleep(delay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment