忍者ブログ
[281]  [280]  [279]  [278]  [277]  [275]  [274]  [273]  [272]  [271]  [270
×

[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()

拍手

PR
カレンダー
03 2025/04 05
S M T W T F S
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
フリーエリア
最新CM
[03/10 DORA]
最新TB
プロフィール
HN:
dorabu
性別:
非公開
バーコード
ブログ内検索
P R
Copyright © ドラブーのアンドロイドとIoTなブログ All rights reserved. / Template by 四季. / Material by てんせん.

忍者ブログ [PR]