×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
Webobを使ってLED三連のONとOFF
1.接続
11----- +緑LED- ---500Ω--GND
13----- +黄LED- ---500Ω--GND
15----- +赤LED- ---500Ω--GND
2.Webobのインストールは以前のブログを参照
import time
import RPi.GPIO as GPIO
from webob import Request, Response
Rpin = 15
Ypin= 13
Gpin = 11
html = """
<form method="post">
<table>
<tr>
<td>RED</td>
<td>YEL</td>
<td>GRE</td>
</tr>
<tr>
<td><input type="submit" name = "button" value = "RON"></td>
<td><input type="submit" name = "button" value ="YON"></td>
<td><input type="submit" name = "button" value ="GON"></td>
</tr>
<tr>
<td><input type="submit" name = "button" value = "ROFF"></td>
<td><input type="submit" name = "button" value ="YOFF"></td>
<td><input type="submit" name = "button" value ="GOFF"></td>
</tr>
</table>
</form>
"""
class WebApp(object):
def __call__(self, environ, start_response):
req = Request(environ)
if req.path == '/':
button = req.params.get('button','')
if (button=='RON') :
GPIO.output(Rpin,GPIO.HIGH)
if (button=='YON') :
GPIO.output(Ypin,GPIO.HIGH)
if (button=='GON') :
GPIO.output(Gpin,GPIO.HIGH)
if (button=='ROFF') :
GPIO.output(Rpin,GPIO.LOW)
if (button=='YOFF') :
GPIO.output(Ypin,GPIO.LOW)
if (button=='GOFF') :
GPIO.output(Gpin,GPIO.LOW)
resp = Response(html)
else:
resp = Response()
return resp(environ ,start_response)
application = WebApp()
def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Rpin,GPIO.OUT)
GPIO.setup(Ypin,GPIO.OUT)
GPIO.setup(Gpin,GPIO.OUT)
def destory():
GPIO.output(Rpin,GPIO.LOW)
GPIO.output(Ypin,GPIO.LOW)
GPIO.output(Gpin,GPIO.LOW)
GPIO.cleanup()
if __name__ == '__main__':
setup()
from wsgiref.simple_server import make_server
port = 8080
httpd = make_server('',port,application)
#print ('serving http port %s...' % port)
try:
httpd.serve_forever() #serverkidou
except KeyboardInterrupt:
destory()
1.接続
11----- +緑LED- ---500Ω--GND
13----- +黄LED- ---500Ω--GND
15----- +赤LED- ---500Ω--GND
2.Webobのインストールは以前のブログを参照
import time
import RPi.GPIO as GPIO
from webob import Request, Response
Rpin = 15
Ypin= 13
Gpin = 11
html = """
<form method="post">
<table>
<tr>
<td>RED</td>
<td>YEL</td>
<td>GRE</td>
</tr>
<tr>
<td><input type="submit" name = "button" value = "RON"></td>
<td><input type="submit" name = "button" value ="YON"></td>
<td><input type="submit" name = "button" value ="GON"></td>
</tr>
<tr>
<td><input type="submit" name = "button" value = "ROFF"></td>
<td><input type="submit" name = "button" value ="YOFF"></td>
<td><input type="submit" name = "button" value ="GOFF"></td>
</tr>
</table>
</form>
"""
class WebApp(object):
def __call__(self, environ, start_response):
req = Request(environ)
if req.path == '/':
button = req.params.get('button','')
if (button=='RON') :
GPIO.output(Rpin,GPIO.HIGH)
if (button=='YON') :
GPIO.output(Ypin,GPIO.HIGH)
if (button=='GON') :
GPIO.output(Gpin,GPIO.HIGH)
if (button=='ROFF') :
GPIO.output(Rpin,GPIO.LOW)
if (button=='YOFF') :
GPIO.output(Ypin,GPIO.LOW)
if (button=='GOFF') :
GPIO.output(Gpin,GPIO.LOW)
resp = Response(html)
else:
resp = Response()
return resp(environ ,start_response)
application = WebApp()
def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Rpin,GPIO.OUT)
GPIO.setup(Ypin,GPIO.OUT)
GPIO.setup(Gpin,GPIO.OUT)
def destory():
GPIO.output(Rpin,GPIO.LOW)
GPIO.output(Ypin,GPIO.LOW)
GPIO.output(Gpin,GPIO.LOW)
GPIO.cleanup()
if __name__ == '__main__':
setup()
from wsgiref.simple_server import make_server
port = 8080
httpd = make_server('',port,application)
#print ('serving http port %s...' % port)
try:
httpd.serve_forever() #serverkidou
except KeyboardInterrupt:
destory()
PR