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 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| import web import RPi.GPIO as GPIO import time import sys import os from array import *
GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) GPIO.setup(22, GPIO.OUT) GPIO.setup(23, GPIO.OUT) GPIO.setup(24, GPIO.OUT) GPIO.setup(25, GPIO.OUT)
urls = ( '/(.*)', 'hello' ) app = web.application(urls, globals())
arr = [0,1,2,3]
ports = [22,23,24,25] def move(d): if d=='left': arr = [0,1,2,3] if d=='right': arr = [3,2,1,0] for x in range(0,40): for j in arr: time.sleep(0.01) for i in range(0,4): if i == j: GPIO.output(ports[i],True) else: GPIO.output(ports[i],False)
class hello: def GET(self, name): if name == 'on': name = 'test' GPIO.output(18,GPIO.HIGH) if name == 'off': GPIO.output(18,GPIO.LOW) if name == 'take': print 'take a photo to /var/www/' os.system('sudo /usr/bin/fswebcam -r 320x240 --no-banner /var/www/a.jpg') if name == 'moveleft': print 'move left' move('left') if name == 'moveright': print 'move right' move('right') if not name: name = 'World' return 'Hello, ' + name + '!'
if __name__ == "__main__": app.run()
|