class SERVO_POT: def __init__(self, baudrate): self.baudrate = baudrate self.setup() self.run() self.exit() def setup(self): self.obj_arduino = Arduino() self.port = self.obj_arduino.locateport() self.obj_arduino.open_serial(1, self.port, self.baudrate) def run(self): self.pin1 = 9 self.pot = 2 self.pos = 0 self.obj_arduino.cmd_servo_attach(1, 1) sleep(1) self.angle = 18 for i in range(100): val = self.obj_arduino.cmd_analog_in(1, self.pot) print val val = int(val * 180 / 1023) print val self.obj_arduino.cmd_servo_move(1, 1, val) sleep(0.5) self.obj_arduino.cmd_servo_detach(1, 1) def exit(self): self.obj_arduino.close_serial()
class SERVO_POT: def __init__(self,baudrate): self.baudrate=baudrate self.setup() self.run() self.exit() def setup(self): self.obj_arduino=Arduino() self.port=self.obj_arduino.locateport() self.obj_arduino.open_serial(1,self.port,self.baudrate) def run(self): self.pin1=9 self.pot=2 self.pos=0 self.obj_arduino.cmd_servo_attach(1,1) sleep(1) self.angle=18 for i in range(100): val=self.obj_arduino.cmd_analog_in(1,self.pot) print val val = int(val*180/1023) print val self.obj_arduino.cmd_servo_move(1,1,val) sleep(0.5) self.obj_arduino.cmd_servo_detach(1,1) def exit(self): self.obj_arduino.close_serial()
class SERVO_INIT: def __init__(self,baudrate): self.baudrate=baudrate self.setup() self.run() self.exit() def setup(self): self.obj_arduino=Arduino() self.port=self.obj_arduino.locateport() self.obj_arduino.open_serial(1,self.port,self.baudrate) def run(self): self.pin1=9 self.obj_arduino.cmd_servo_attach(1,1) self.obj_arduino.cmd_servo_move(1,1,30) sleep(1) self.obj_arduino.cmd_servo_detach(1,1) sleep(1) def exit(self): self.obj_arduino.close_serial()
class SOLAR_TRACKER: def __init__(self,baudrate): self.baudrate=baudrate self.setup() self.run() self.exit() def setup(self): self.obj_arduino=Arduino() self.port=self.obj_arduino.locateport() #Locates the port self.obj_arduino.open_serial(1,self.port,self.baudrate) def run(self): self.ldr1=0 #LDR1 connected at port 0 self.ldr2=1 #LDR2 connected at port 1 s=0 self.angle=5 # Step angle self.initial=90 self.obj_arduino.cmd_servo_attach(1,1) # Attach the servo at pin 9 sleep(1) self.obj_arduino.cmd_servo_move(1,1,self.initial) #Rotate servo by 90 deg sleep(1) for i in range(20): p=self.obj_arduino.cmd_analog_in(1,self.ldr1) #Read analog input from LDR1 q=self.obj_arduino.cmd_analog_in(1,self.ldr2) # Read analog input from LDR2 print p print q sleep(1) if int(p) < int(q): s=s+1 self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s) # Clockwise rotation sleep(1) else: s=s-1 self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s) # Anti-clockwise rotation sleep(1) self.obj_arduino.cmd_servo_detach(1,1) # Detach the motor def exit(self): self.obj_arduino.close_serial() # Close the serial port
class SERVO_INIT: def __init__(self, baudrate): self.baudrate = baudrate self.setup() self.run() self.exit() def setup(self): self.obj_arduino = Arduino() self.port = self.obj_arduino.locateport() self.obj_arduino.open_serial(1, self.port, self.baudrate) def run(self): self.pin1 = 9 self.obj_arduino.cmd_servo_attach(1, 1) self.obj_arduino.cmd_servo_move(1, 1, 30) sleep(1) self.obj_arduino.cmd_servo_detach(1, 1) sleep(1) def exit(self): self.obj_arduino.close_serial()