4th Draft
4th Draft
4th Draft
GPIO as GPIO
from http.server import BaseHTTPRequestHandler, HTTPServer
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
servo1= GPIO.PWM(23, 100)
GPIO.setup(12, GPIO.OUT)
servo2= GPIO.PWM(12, 100)
Input = None
class RequestHandler_httpd(BaseHTTPRequestHandler):
def do_GET(self):
global Input
messagetosend = bytes("Clare's Rpi","utf")
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.send_header('Content-Length', len(messagetosend))
self.end_headers()
self.wfile.write(messagetosend.encode('utf-8'))
float(Input) = self.requestline
Input = Input[5 : int(len(Input)-9)]
print(Input)
if 0 < Input <= 4:
dutyCycle = ((float(60) * 0.01) + 0.5) * 10
servo1.ChangeDutyCycle(dutyCycle)
for count in range(10):
dutyCycle = ((float(180) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
break
dutyCycle = ((float(0) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
if 4 < Input <= 8:
dutyCycle = ((float(120) * 0.01) + 0.5) * 10
servo1.ChangeDutyCycle(dutyCycle)
for count2 in range(10):
dutyCycle = ((float(180) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
break
dutyCycle = ((float(0) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
if 8 < Input <= 12:
dutyCycle = ((float(180) * 0.01) + 0.5) * 10
servo1.ChangeDutyCycle(dutyCycle)
for count3 in range(10):
dutyCycle = ((float(180) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
break
dutyCycle = ((float(0) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
if 12 < Input <= 16:
dutyCycle = ((float(240) * 0.01) + 0.5) * 10
servo1.ChangeDutyCycle(dutyCycle)
for count4 in range(10):
dutyCycle = ((float(180) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
break
dutyCycle = ((float(0) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
if 16 < Input <= 20:
dutyCycle = ((float(300) * 0.01) + 0.5) * 10
servo1.ChangeDutyCycle(dutyCycle)
for count5 in range(10):
dutyCycle = ((float(180) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
break
dutyCycle = ((float(0) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
if 20 < Input <= 24:
dutyCycle = ((float(360) * 0.01) + 0.5) * 10
servo1.ChangeDutyCycle(dutyCycle)
for count6 in range(10):
dutyCycle = ((float(180) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
break
dutyCycle = ((float(0) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
return
servo1.start(10)
servo2.start(10)
dutyCycle = ((float(0) * 0.01) + 0.5) * 10
servo2.ChangeDutyCycle(dutyCycle)
server_address_httpd = ('192.168.1.17',8080)
httpd = HTTPServer(server_address_httpd, RequestHandler_httpd)
print('Starting Server...')
httpd.serve_forever()
GPIO.cleanup()