-
Notifications
You must be signed in to change notification settings - Fork 0
/
leds.py
58 lines (42 loc) · 1.35 KB
/
leds.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import RPi.GPIO as GPIO
import time
class right_led(object):
def __init__(self):
GPIO.setmode(GPIO.BCM)
self.LED_GPIO = 18
GPIO.setup(self.LED_GPIO, GPIO.OUT)
def turn_on(self):
self.turned_on = True
my_pwm = GPIO.PWM(self.LED_GPIO, 100) # PIN / FREQUENCY
my_pwm.start(0) # duty_cycle = 50% up and 50% down
for i in range(100):
time.sleep(0.05)
my_pwm.ChangeDutyCycle(i)
my_pwm.ChangeDutyCycle(0)
time.sleep (0.3)
my_pwm.ChangeDutyCycle(100)
while self.turned_on == True:
time.sleep(0.5)
print "right led off "
def turn_off(self):
self.turned_on = False
class left_led(object):
def __init__(self):
GPIO.setmode(GPIO.BCM)
self.LED_GPIO = 23
GPIO.setup(self.LED_GPIO, GPIO.OUT)
def turn_on(self):
self.turned_on = True
my_pwm = GPIO.PWM(self.LED_GPIO, 100) # PIN / FREQUENCY
my_pwm.start(0) # duty_cycle = 50% up and 50% down
for i in range(100):
time.sleep(0.05)
my_pwm.ChangeDutyCycle(i)
my_pwm.ChangeDutyCycle(0)
time.sleep (0.3)
my_pwm.ChangeDutyCycle(100)
while self.turned_on == True:
time.sleep(0.5)
print "right led off "
def turn_off(self):
self.turned_on = False