How to control the RGB light of raspberry pie through WEB
This article mainly shows you "how to control raspberry pie RGB lights through WEB". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to control raspberry pie RGB lights through WEB".
Main.py:
01 #! / usr/bin/env python302 03 import RPi.GPIO as GPIO04 from RGB_light import RGB_light05 from bottle import request, route, run, static_file # bottle introduction: https://git.oschina.net/ginnywzj/web_rgb/attach_files06 import time, threading07 08 rgb = 009 RGBLight = RGB_light (GPIO.BOARD, 1,33,35,37) # initialize rgb lamp GPIO pin, pin numbering system is GPIO.BOARD, common positive, red channel is 33 pin, green channel is 35 pin Blue channel is 37-pin s10 light_type = 'static' #' static': static 'breath': breath' flash': flashes 11 12 # access file root directory 13 @ route ('/') 14 def index (): 15 global rgb, light_type16 rgb = 0xffffff17 light_type = 'static'18 return static_file (' index.html' '. / page') 19 20 # static files need to be transferred 21 @ route (' /') 22 def server_static (filename): 23 return static_file (filename, root='./page') 24 25 # POST to obtain the RGB value 26 @ route ('/ rgb') transmitted by Ajax Method='POST') 27 def rgbLight (): 28 red= request.POST.get ('red') 29 green= request.POST.get (' green') 30 blue= request.POST.get ('blue') 31 print (' red='+ red +', green='+ green +', blue='+ blue) 32 red= int (red) 33 green= int (green) 34 blue= int (blue) 35 if 0 07