def connectBot(self): self.ble = BLE() if botName != "": self.myBot = self.ble.findNearest() else: self.myBot = self.ble.findByName(botName) self.joypadClient = SimpleJoypadClient(self.myBot)
def main(): xAxis = 0 yAxis = 0 lastUpdateTime = time.time() joysticks = [] clock = pygame.time.Clock() keepPlaying = True ble = BLE() myBot = ble.findNearest() joypadClient = SimpleJoypadClient(myBot) # for al the connected joysticks for i in range(0, pygame.joystick.get_count()): # create an Joystick object in our list joysticks.append(pygame.joystick.Joystick(i)) # initialize them all (-1 means loop forever) joysticks[-1].init() # print a statement telling what the name of the controller is print "Detected joystick '", joysticks[-1].get_name(), "'" while keepPlaying: if (time.time() - lastUpdateTime) > 0.05: joypadClient.updateJoypadWithZ(int(xAxis * 255), int(yAxis * 255), 0, 0) lastUpdateTime = time.time() clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: print "Received event 'Quit', exiting." keepPlaying = False elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: print "Escape key pressed, exiting." keepPlaying = False elif event.type == pygame.JOYAXISMOTION: #print "Joystick '",joysticks[event.joy].get_name(),"' axis",event.axis,"motion." if event.axis == 0: xAxis = joysticks[-1].get_axis(0) if event.axis == 1: yAxis = joysticks[-1].get_axis(1) elif event.type == pygame.JOYBUTTONDOWN: print "Joystick '", joysticks[ event.joy].get_name(), "' button", event.button, "down." elif event.type == pygame.JOYBUTTONUP: print "Joystick '", joysticks[ event.joy].get_name(), "' button", event.button, "up." elif event.type == pygame.JOYHATMOTION: print "Joystick '", joysticks[ event.joy].get_name(), "' hat", event.hat, " moved."
def main(): xAxis=0 yAxis=0 lastUpdateTime = time.time() joysticks = [] clock = pygame.time.Clock() keepPlaying = True ble = BLE() myBot = ble.findNearest() joypadClient = SimpleJoypadClient(myBot) # for al the connected joysticks for i in range(0, pygame.joystick.get_count()): # create an Joystick object in our list joysticks.append(pygame.joystick.Joystick(i)) # initialize them all (-1 means loop forever) joysticks[-1].init() # print a statement telling what the name of the controller is print "Detected joystick '",joysticks[-1].get_name(),"'" while keepPlaying: if (time.time() - lastUpdateTime) > 0.05: joypadClient.updateJoypadWithZ(int(xAxis*255), int(yAxis*255), 0,0) lastUpdateTime=time.time() clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: print "Received event 'Quit', exiting." keepPlaying = False elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: print "Escape key pressed, exiting." keepPlaying = False elif event.type == pygame.JOYAXISMOTION: #print "Joystick '",joysticks[event.joy].get_name(),"' axis",event.axis,"motion." if event.axis==0: xAxis=joysticks[-1].get_axis(0) if event.axis==1: yAxis=joysticks[-1].get_axis(1) elif event.type == pygame.JOYBUTTONDOWN: print "Joystick '",joysticks[event.joy].get_name(),"' button",event.button,"down." elif event.type == pygame.JOYBUTTONUP: print "Joystick '",joysticks[event.joy].get_name(),"' button",event.button,"up." elif event.type == pygame.JOYHATMOTION: print "Joystick '",joysticks[event.joy].get_name(),"' hat",event.hat," moved."
#!/usr/bin/python from time import sleep from cannybots.radio import BLE from cannybots.clients.joypad import SimpleJoypadClient ble = BLE() myBot = ble.findNearest() joypadClient = SimpleJoypadClient(myBot) joypadClient.updateJoypad(255, 255, 0) sleep(1) joypadClient.updateJoypad(-255, -255, 0) sleep(1) joypadClient.updateJoypad(0, 0, 0) sleep(2)
#!/usr/bin/python from time import sleep from cannybots.radio import BLE from cannybots.clients.joypad import SimpleJoypadClient ble = BLE() myBot = ble.findNearest() joypadClient = SimpleJoypadClient(myBot) joypadClient.updateJoypad(255,255,0) sleep(1) joypadClient.updateJoypad(-255,-255,0) sleep(1) joypadClient.updateJoypad(0,0,0) sleep(2)
#!/usr/bin/python # # Cannybots Scratch integration # By Wayne Keenan 02/12/2014 # www.cannybots.com from scratra import * from time import sleep from cannybots.radio import BLE from cannybots.clients.joypad import SimpleJoypadClient ble = BLE() myBot = ble.findNearest() joypadClient = SimpleJoypadClient(myBot) motorASpeed = 0 motorBSpeed = 0 @start def whenstart(scratch): print 'Scratch connection started.' @end def whenend(scratch): print 'Scratch connection ended' @broadcast('CB_FORWARD')