Skip to content

Instantly share code, notes, and snippets.

@jadonk
Last active October 1, 2024 16:32
Show Gist options
  • Save jadonk/86b6e9d61ece41e26366d26a3aae380a to your computer and use it in GitHub Desktop.
Save jadonk/86b6e9d61ece41e26366d26a3aae380a to your computer and use it in GitHub Desktop.
import time
import datetime
import gpiod
gpio2 = gpiod.find_line('GPIO2')
gpio2.request(consumer='five_min_toggle', type=gpiod.LINE_REQ_DIR_OUT, default_val=0)
prev_rem = -1
while True:
now = datetime.datetime.now()
min = datetime.datetime.now().minute
rem = ((min // 5) % 2)
if rem == 0 and prev_rem != 0:
print("Setting GPIO low")
prev_rem = 0
gpio2.set_value(0)
elif rem == 1 and prev_rem != 1:
print("Setting GPIO high")
prev_rem = 1
gpio2.set_value(1)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment