-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled.py
36 lines (29 loc) · 855 Bytes
/
led.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
import logging
import RPi.GPIO as GPIO
import time
DURATION_VERY_SHORT = 0.2
DURATION_SHORT = 0.5
DURATION_NORMAL = 1
class Led(object):
"""An LED class"""
def __init__(self, pin, name):
self.pin = pin
self.name = name
# Setup GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, False)
def blink(self, duration=DURATION_NORMAL):
"""Blink once"""
print 'Led blink'
GPIO.output(self.pin, True)
time.sleep(duration)
GPIO.output(self.pin, False)
def blink_for(self, times=10, light=DURATION_NORMAL, sleep=DURATION_NORMAL):
"""Blink specifying time, light duration and sleep duration"""
for x in range(0, times):
self.blink(light)
time.sleep(sleep)
def blink_twice(self):
"""Blink twice"""
self.blink_for(2, DURATION_VERY_SHORT, DURATION_VERY_SHORT)