-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path08_breathingLed.py
More file actions
executable file
·39 lines (32 loc) · 1.06 KB
/
08_breathingLed.py
File metadata and controls
executable file
·39 lines (32 loc) · 1.06 KB
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
36
37
38
#!/usr/bin/env python
#-----------------------------------------------------------
# File name : 08_breathingLed.py
# Description : breathing LED.
# Author : Jason
# E-mail : jason@adeept.com
# Website : www.adeept.com
# Date : 2015/06/12
#-----------------------------------------------------------
import RPi.GPIO as GPIO
import time
LedPin = 12
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
GPIO.setup(LedPin, GPIO.OUT) # Set pin mode as output
GPIO.output(LedPin, GPIO.LOW) # Set pin to low(0V)
p = GPIO.PWM(LedPin, 1000) # set Frequece to 1KHz
p.start(0) # Start PWM output, Duty Cycle = 0
try:
while True:
for dc in range(0, 101, 4): # Increase duty cycle: 0~100
p.ChangeDutyCycle(dc) # Change duty cycle
time.sleep(0.05)
time.sleep(1)
for dc in range(100, -1, -4): # Decrease duty cycle: 100~0
p.ChangeDutyCycle(dc)
time.sleep(0.05)
time.sleep(1)
except KeyboardInterrupt:
p.stop()
GPIO.output(LedPin, GPIO.HIGH) # turn off all leds
GPIO.cleanup()