def createMotor(pin1, pin2, pin3, pin4, command_index): pin1 = int(pin1) pin2 = int(pin2) pin3 = int(pin3) pin4 = int(pin4) command_index = int(command_index) motor = Motor([pin1,pin2,pin3,pin4], 15) motor.move_to(180)
def createMotor(pin1, pin2, pin3, pin4, command_index): pin1 = int(pin1) pin2 = int(pin2) pin3 = int(pin3) pin4 = int(pin4) command_index = int(command_index) motor = Motor([pin1, pin2, pin3, pin4], 15) motor.move_to(180)
class MotorThread(threading.Thread): def __init__(self, pin1, pin2, pin3, pin4, command_index): threading.Thread.__init__(self) self.pin1 = int(pin1) self.pin2 = int(pin2) self.pin3 = int(pin3) self.pin4 = int(pin4) self.command_index = int(command_index) self.motor = Motor([int(self.pin1), int(self.pin2), int(self.pin3), int(self.pin4)], 15) def run(self): self.motor.move_to(90)
class MotorThread(threading.Thread): def __init__(self, pin1, pin2, pin3, pin4, command_index): threading.Thread.__init__(self) self.pin1 = int(pin1) self.pin2 = int(pin2) self.pin3 = int(pin3) self.pin4 = int(pin4) self.command_index = int(command_index) self.motor = Motor( [int(self.pin1), int(self.pin2), int(self.pin3), int(self.pin4)], 15) def run(self): self.motor.move_to(90)
#!/usr/bin/python from Stepper import Motor from time import sleep import RPi.GPIO as GPIO import sys if __name__ == "__main__": GPIO.setmode(GPIO.BOARD) m = Motor([ int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]) ], 15) # clock 180 m.move_to(180) sleep(0.2) m.move_to(270) sleep(0.5) m.move_to(0) m.move_to(-90) GPIO.cleanup()
#!/usr/bin/python from Stepper import Motor from time import sleep import RPi.GPIO as GPIO import sys if __name__ == "__main__": GPIO.setmode(GPIO.BCM) m = Motor([18,23,24,25], 15) # clock 180 m.move_to(20)
#!/usr/bin/python from Stepper import Motor from time import sleep import RPi.GPIO as GPIO import sys if __name__ == "__main__": GPIO.setmode(GPIO.BOARD) m = Motor([int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3]),int(sys.argv[4])], 15) # clock 180 m.move_to(180) sleep(0.2) m.move_to(270) sleep(0.5) m.move_to(0) m.move_to(-90) GPIO.cleanup()
csock, caddr = sock.accept() print datetime.today() print "Connection from: " + ` caddr ` req = csock.recv(1024) # get the request, 1kB max req = req.split("\n")[0] print "Request: " + req # Look in the first line of the request for a move command # A move command should be e.g. 'http://server/move?a=90' match_angle = re.match('GET /move\?a=(\d+)\sHTTP/1', req) match_location = re.match('GET /move\?l=(\w+)\sHTTP/1', req) if match_angle: angle = int(match_angle.group(1)) print "Angle: " + ` angle ` csock.sendall("HTTP/1.0 200 OK\r\n\r\n") print "Moving motor..." motor.move_to(angle) elif match_location: loc = match_location.group(1) try: print "Location: " + loc angle = location[loc] print "Angle: " + ` angle ` csock.sendall("HTTP/1.0 200 OK\r\n\r\n") print "Moving motor..." sound.play() motor.move_to(angle) except KeyError: print "Location " + loc + " is unknown, returning 501" csock.sendall("HTTP/1.0 501 Not Implemented\r\n\r\n") else: # If there was no recognised command then return a 404 (page not found)
csock, caddr = sock.accept() print datetime.today() print "Connection from: " + `caddr` req = csock.recv(1024) # get the request, 1kB max req = req.split("\n")[0] print "Request: " + req # Look in the first line of the request for a move command # A move command should be e.g. 'http://server/move?a=90' match_angle = re.match('GET /move\?a=(\d+)\sHTTP/1', req) match_location = re.match('GET /move\?l=(\w+)\sHTTP/1', req) if match_angle: angle = int(match_angle.group(1)) print "Angle: " + `angle` csock.sendall("HTTP/1.0 200 OK\r\n\r\n") print "Moving motor..." motor.move_to(angle) elif match_location: loc = match_location.group(1) try: print "Location: " + loc angle = location[loc] print "Angle: " + `angle` csock.sendall("HTTP/1.0 200 OK\r\n\r\n") print "Moving motor..." sound.play() motor.move_to(angle) except KeyError: print "Location " + loc + " is unknown, returning 501" csock.sendall("HTTP/1.0 501 Not Implemented\r\n\r\n") else: # If there was no recognised command then return a 404 (page not found)