Last active
October 1, 2024 16:32
-
-
Save jadonk/86b6e9d61ece41e26366d26a3aae380a to your computer and use it in GitHub Desktop.
This file contains 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
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