def write(self, power): self.value = power _grab_read() try: return_value = gopigo.analogWrite(self.getPortID(), power) except: pass _release_read() return return_value
def write(self, power): self.value = power _ifMutexAcquire(self.use_mutex) try: return_value = gopigo.analogWrite(self.getPortID(), power) except: pass finally: _ifMutexRelease(self.use_mutex) return return_value
def write(self, power): self.value = power return gopigo.analogWrite(self.getPortID(), power)
def process_command(self, command): parts = command.split("/") if parts[1] == "poll": print "poll" self.us_dist = gopigo.us_dist(usdist_pin) self.enc_status = gopigo.read_status()[0] self.volt = gopigo.volt() self.fw_ver = gopigo.fw_ver() self.trim = gopigo.trim_read() - 100 if self.enc_status == 0: self.waitingOn = None elif parts[1] == "stop": gopigo.stop() elif parts[1] == "trim_write": gopigo.trim_write(int(parts[2])) self.trim = gopigo.trim_read() elif parts[1] == "trim_read": self.trim = gopigo.trim_read() - 100 elif parts[1] == "set_speed": if parts[2] == "left": self.left_speed = int(parts[3]) elif parts[2] == "right": self.right_speed = int(parts[3]) else: self.right_speed = int(parts[3]) self.left_speed = int(parts[3]) gopigo.set_left_speed(self.left_speed) gopigo.set_right_speed(self.right_speed) elif parts[1] == "leds": val = 0 if parts[3] == "on": val = 1 elif parts[3] == "off": val = 0 elif parts[3] == "toggle": val = -1 if parts[2] == "right" or parts[2] == "both": if val >= 0: self.ledr = val else: self.ledr = 1 - self.ledr if parts[2] == "left" or parts[2] == "both": if val >= 0: self.ledl = val else: self.ledl = 1 - self.ledl gopigo.digitalWrite(ledr_pin, self.ledr) gopigo.digitalWrite(ledl_pin, self.ledl) elif parts[1] == "servo": gopigo.servo(int(parts[2])) elif parts[1] == "turn": self.waitingOn = parts[2] direction = parts[3] amount = int(parts[4]) encleft = 0 if direction == "left" else 1 encright = 1 if direction == "left" else 0 gopigo.enable_encoders() gopigo.enc_tgt(encleft, encright, int(amount / DPR)) if direction == "left": gopigo.left() else: gopigo.right() elif parts[1] == "move": self.waitingOn = int(parts[2]) direction = parts[3] amount = int(parts[4]) gopigo.enable_encoders() gopigo.enc_tgt(1, 1, amount) if direction == "backward": gopigo.bwd() else: gopigo.fwd() elif parts[1] == "beep": gopigo.analogWrite(buzzer_pin, self.beep_volume) time.sleep(self.beep_time) gopigo.analogWrite(buzzer_pin, 0) elif parts[1] == "reset_all": self.ledl = 0 self.ledr = 0 gopigo.digitalWrite(ledl_pin, self.ledl) gopigo.digitalWrite(ledr_pin, self.ledr) gopigo.analogWrite(buzzer_pin, 0) # gopigo.servo(90) gopigo.stop()
import time import gopigo # Connect the Grove LED to digital port D10 # The pin should be 10 for the D10 digital port or you can call digitalPort definition from the GoPiGo library # The LED won't work on any other port other than D10 when using fade led_pin = gopigo.digitalPort gopigo.pinMode(led_pin, "OUTPUT") i = 0 while True: try: # Reset if i > 255: i = 0 # Current brightness print (i) # Give PWM output to LED gopigo.analogWrite(led_pin, i) # Increment brightness for next iteration i = i + 20 time.sleep(.5) except IOError: print ("Error")
''' import time import gopigo # Connect the Grove LED to digital port D10 # The pin should be 10 for the D10 digital port or you can call digitalPort definition from the GoPiGo library # The LED won't work on any other port other than D10 when using fade led_pin = gopigo.digitalPort gopigo.pinMode(led_pin,"OUTPUT") i=0 while True: try: # Reset if i > 255: i = 0 # Current brightness print (i) # Give PWM output to LED gopigo.analogWrite(led_pin,i) # Increment brightness for next iteration i = i + 20 time.sleep(.5) except IOError: print ("Error")
def write(self, power): self.value = power I2C_Mutex_Acquire() return_value = gopigo.analogWrite(self.getPortID(), power) I2C_Mutex_Release() return return_value
def analogWrite(kargs): r = {'return_value': gopigo.analogWrite(int(kargs['pin']), int(kargs['value']))} return r