-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathled.py
executable file
·39 lines (34 loc) · 1.4 KB
/
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
import web
import RPi.GPIO as GPIO
from web import form
GPIO.setmode(GPIO.BOARD) ## setting GPIO pin numbering to Board format
GPIO.setup(7, GPIO.OUT) ## Setting GPIO Pin 7 to Output mode
#Defining the index page
urls = ('/', 'index')
render = web.template.render('templates') #index.html is stored in '/templates' folder
app = web.application(urls, globals())
""" Defining the buttons. 'id' stands for HTML id of the element. 'value' is the value of the button as perceived by Python. 'html' is the text displayed in HTML page. 'class_' is HTML class"""
my_form = form.Form(
form.Button("btn", id="btnR", value="on", html="on", class_="on"),
form.Button("btn", id="btnG", value="off", html="off", class_="off"),
)
# define the task of index page
class index:
# rendering the HTML page
def GET(self):
form = my_form()
return render.index(form, "Raspberry Pi LED Blink")
# posting the data from the webpage to Pi
def POST(self):
# get the data submitted from the web form
userData = web.input()
if userData.btn == "on":
GPIO.output(7,True) #Turn on the LED
print "LED is ON" #prints the status in Pi's Terminal
elif userData.btn == "off":
GPIO.output(7,False) #Turn of the LED
print "LED is OFF" #prints the status in Pi's Terminal
raise web.seeother('/')
# run
if __name__ == '__main__':
app.run()