-
Notifications
You must be signed in to change notification settings - Fork 97
/
grove_led.py
79 lines (60 loc) · 1.61 KB
/
grove_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# The MIT License (MIT)
#
# Grove Base Hat for the Raspberry Pi, used to connect grove sensors.
# Copyright (C) 2018 Seeed Technology Co.,Ltd.
'''
This is the code for
- `Grove - Red LED <https://www.seeedstudio.com/Grove-Red-LED-p-1142.html>`_
- `Grove - Green LED <https://www.seeedstudio.com/Grove-Green-LED-p-1144.html>`_
- `Grove - Purple LED <https://www.seeedstudio.com/Grove-Purple-LED-3m-p-1143.html>`_
- `Grove - White LED <https://www.seeedstudio.com/Grove-White-LED-p-1140.html>`_
Examples:
.. code-block:: python
import time
from grove.grove_led import GroveLed
# connect to pin 5(slot D5)
PIN = 5
led = GroveLed(PIN)
while True:
led.on()
time.sleep(1)
led.off()
time.sleep(1)
'''
import time
from grove.gpio import GPIO
__all__ = ['GroveLed', 'GPIO']
class GroveLed(GPIO):
'''
Class for Grove - XXXX Led
Args:
pin(int): number of digital pin the led connected.
'''
def __init__(self, pin):
super(GroveLed, self).__init__(pin, GPIO.OUT)
def on(self):
'''
light on the led
'''
self.write(1)
def off(self):
'''
light off the led
'''
self.write(0)
Grove = GroveLed
def main():
from grove.helper import SlotHelper
sh = SlotHelper(SlotHelper.GPIO)
pin = sh.argv2pin()
led = GroveLed(pin)
while True:
led.on()
time.sleep(1)
led.off()
time.sleep(1)
if __name__ == '__main__':
main()