-
Notifications
You must be signed in to change notification settings - Fork 0
/
heartbeatsync.py
35 lines (29 loc) · 1.18 KB
/
heartbeatsync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import RPi.GPIO as GPIO
import time
# Set up GPIO using BCM numbering
GPIO.setmode(GPIO.BOARD)
# Set the GPIO pin to output mode
led_pin = 3
GPIO.setup(led_pin, GPIO.OUT)
# Define the number of steps and duration for the fade in/out effect
num_steps = 50
fade_duration = 0.5 / num_steps # Total duration divided by number of steps
try:
while True:
# Fade in
for i in range(num_steps):
brightness = i / num_steps
GPIO.output(led_pin, True) # Turn on the LED
time.sleep(fade_duration) # Wait for the fade duration
GPIO.output(led_pin, False) # Turn off the LED
time.sleep(fade_duration * (1 - brightness)) # Adjust the off time based on brightness
# Fade out
for i in range(num_steps, 0, -1):
brightness = i / num_steps
GPIO.output(led_pin, True) # Turn on the LED
time.sleep(fade_duration) # Wait for the fade duration
GPIO.output(led_pin, False) # Turn off the LED
time.sleep(fade_duration * (1 - brightness)) # Adjust the off time based on brightness
except KeyboardInterrupt:
# Clean up GPIO on keyboard interrupt
GPIO.cleanup()