-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled.py
More file actions
51 lines (38 loc) · 889 Bytes
/
led.py
File metadata and controls
51 lines (38 loc) · 889 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
class Led:
def __init__(self,name,pin):
self.name = name
self.pin = pin
self.status = False
GPIO.setup(pin, GPIO.OUT)
def on(self):
print self.name + " led on"
GPIO.output(self.pin, GPIO.HIGH)
self.status = True
def off(self):
print self.name + " led off"
GPIO.output(self.pin, GPIO.LOW)
self.status = False
def toggle(self):
if(self.status):
self.off()
else:
self.on()
class Handler:
def __init__(self):
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
self.red = Led('red',21)
self.green = Led('green',20)
self.yellow = Led('yellow',16)
self.blue = Led('blue',19)
def toggleRedLed(self):
self.red.toggle()
def toggleGreenLed(self):
self.green.toggle()
def toggleYellowLed(self):
self.yellow.toggle()
def toggleBlueLed(self):
self.blue.toggle()