def __init__(self): self.on_button_a = None # Set up the game pad self._pad = GamePadShift(DigitalInOut(board.BUTTON_CLOCK), DigitalInOut(board.BUTTON_OUT), DigitalInOut(board.BUTTON_LATCH))
def __init__(self): super().__init__() i2c = None if i2c is None: try: i2c = board.I2C() except RuntimeError: self._accelerometer = None if i2c is not None: int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) try: self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1) except ValueError: self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) # NeoPixels self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB) self._buttons = GamePadShift( digitalio.DigitalInOut(board.BUTTON_CLOCK), digitalio.DigitalInOut(board.BUTTON_OUT), digitalio.DigitalInOut(board.BUTTON_LATCH), ) self._light_sensor = analogio.AnalogIn(board.A7)
def _init_hardware(self): """Initializes PyBadge or PyGamer hardware.""" if hasattr(board, "BUTTON_CLOCK") and not hasattr(board, "JOYSTICK_X"): self._pad_btns = { "btn_left": PYBADGE_BUTTON_LEFT, "btn_right": PYBADGE_BUTTON_RIGHT, "btn_up": PYBADGE_BUTTON_UP, "btn_down": PYBADGE_BUTTON_DOWN, "btn_a": PYBADGE_BUTTON_A, } elif hasattr(board, "JOYSTICK_X"): self._joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) self._pad_btns = {"btn_a": PYBADGE_BUTTON_A} # Sample the center points of the joystick self._center_x = self._joystick_x.value self._center_y = self._joystick_y.value else: raise AttributeError( "Board must have a D-Pad or Joystick for use with CursorManager!" ) self._pad = GamePadShift( digitalio.DigitalInOut(board.BUTTON_CLOCK), digitalio.DigitalInOut(board.BUTTON_OUT), digitalio.DigitalInOut(board.BUTTON_LATCH), )
def __init__(self, lights=None, i2c=None): # Buttons self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK), digitalio.DigitalInOut(board.BUTTON_OUT), digitalio.DigitalInOut(board.BUTTON_LATCH)) self.button_values = self._buttons.get_pressed() self.lights = lights
def init(): game={} DSP=board.DISPLAY ; game['DSP']=DSP game['face_right'] = True game['hero_base'] = 36 # game['gamepad'] = GamePadShift( digitalio.DigitalInOut(board.BUTTON_CLOCK), digitalio.DigitalInOut(board.BUTTON_OUT), digitalio.DigitalInOut(board.BUTTON_LATCH) ) # game['terrMap']={} ; i=0 for c in ' (_)"[#]RGBYOoX^CDEF': game['terrMap'][c]=i ; i+=1 # game['group']=displayio.Group(max_size=8) # util.init_tilegrid(game, "terrain","map", 10,8,16,16, 0,0) util.init_label(game, "label1", terminalio.FONT, 26, 0x0000FF, 0, 0, "") util.init_sprite(game, "heroes","hero", 1,1,16,24, 32,68) util.init_tilegrid(game, "explosions","exp", 1,1,32,32, -32,-32) # DSP.show(game['group']) # game['expName'] = 'exp1' game['exp1'] = [0,1,2,3,4,5,6,7,8,9,10,11,20,21,22,23,24,25,26,27,28,29,30,31] game['exp2'] = [ 1 , 2 , 3 ] # return game
def init(): game={} game['gamepad']=GamePadShift(DigitalInOut(board.BUTTON_CLOCK),DigitalInOut(board.BUTTON_OUT),DigitalInOut(board.BUTTON_LATCH)) DSP=board.DISPLAY ; game['DSP']=DSP # game['terrMap']={} ; i=0 for c in ' (_)"[#]RGBYOoX^CDEF': game['terrMap'][c]=i ; i+=1 # game['group']=displayio.Group(max_size=8) # init_tilegrid(game, "terrain","jokeRoom", 10,6,16,16, 0,16) # init_label(game, "textT", terminalio.FONT, 26, 0xFF00FF, 1, -33, "") init_label(game, "textB", terminalio.FONT, 26, 0x00FFFF, 1, -33, "") # init_tilegrid(game, "rugrats","rugrat1", 1,1,16,24, 32,68) init_tilegrid(game, "pets","pet1", 1,1,32,32, -33,-33) init_tilegrid(game, "snacks","snack1", 1,1,32,32, -33,-33) init_tilegrid(game, "sillies","silly1", 1,1,32,32, -33,-33) # font = bitmap_font.load_font("/dad/fonts/Helvetica-Bold-16.bdf") init_label(game, "textM", font, 18, 0xFFFF00, 8, -33, "") # DSP.show(game['group']) ; DSP.wait_for_frame() # return game
def __init__(self, i2c=None, *, pixels_brightness=1.0): # Accelerometer if i2c is None: try: i2c = board.I2C() except RuntimeError: self._accelerometer = None if i2c is not None: int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) try: self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1) except ValueError: self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) # Buttons self._buttons = GamePadShift( digitalio.DigitalInOut(board.BUTTON_CLOCK), digitalio.DigitalInOut(board.BUTTON_OUT), digitalio.DigitalInOut(board.BUTTON_LATCH)) # Display self.display = board.DISPLAY self._display_brightness = 1.0 # Light sensor self._light_sensor = analogio.AnalogIn(board.A7) # PyGamer joystick if hasattr(board, "JOYSTICK_X"): self._pygamer_joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._pygamer_joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) # NeoPixels # Count is hardcoded - should be based on board ID, currently no board info for PyBadge LC neopixel_count = 5 self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, neopixel_count, brightness=pixels_brightness, pixel_order=neopixel.GRB) # Auto dim display based on movement self._last_accelerometer = None self._start_time = time.monotonic() # Define audio: self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(value=False) self._sample = None self._sine_wave = None self._sine_wave_sample = None
def __init__(self, clock_pin, clock_name, data_pin, data_name, latch_pin, latch_name): self.clock_pin = DigitalInOut(clock_pin) self.data_pin = DigitalInOut(data_pin) self.latch_pin = DigitalInOut(latch_pin) self.clock_name = clock_name self.data_name = data_name self.latch_name = latch_name self.gamepad = GamePadShift(self.clock_pin, self.data_pin, self.latch_pin, 16)
def _init_hardware(self): """Initializes PyBadge or PyGamer hardware.""" if hasattr(board, 'BUTTON_CLOCK') and not hasattr(board, 'JOYSTICK_X'): self._pad_btns = { 'btn_left': PYBADGE_BUTTON_LEFT, 'btn_right': PYBADGE_BUTTON_RIGHT, 'btn_up': PYBADGE_BUTTON_UP, 'btn_down': PYBADGE_BUTTON_DOWN, 'btn_a': PYBADGE_BUTTON_A } elif hasattr(board, 'JOYSTICK_X'): self._joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) self._pad_btns = {'btn_a': PYBADGE_BUTTON_A} else: raise AttributeError( 'Board must have a D-Pad or Joystick for use with CursorManager!' ) self._pad = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK), digitalio.DigitalInOut(board.BUTTON_OUT), digitalio.DigitalInOut(board.BUTTON_LATCH))
def __init__(self): super().__init__() i2c = board.I2C() int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) try: self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1) except ValueError: self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) self._buttons = GamePadShift( digitalio.DigitalInOut(board.BUTTON_CLOCK), digitalio.DigitalInOut(board.BUTTON_OUT), digitalio.DigitalInOut(board.BUTTON_LATCH)) self._pygamer_joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._pygamer_joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) self._light_sensor = analogio.AnalogIn(board.A7)
tile_grid = displayio.TileGrid(bitmap, pixel_shader=displayio.ColorConverter()) # Create a Group to hold the TileGrid group = displayio.Group() # Add the TileGrid to the Group group.append(tile_grid) # Add the Group to the Display display.show(group) show_rainbow = False blackout() pad = GamePadShift(DigitalInOut(board.BUTTON_CLOCK), DigitalInOut(board.BUTTON_OUT), DigitalInOut(board.BUTTON_LATCH)) # Button Constants BUTTON_LEFT = 128 BUTTON_UP = 64 BUTTON_DOWN = 32 BUTTON_RIGHT = 16 BUTTON_SEL = 8 BUTTON_START = 4 BUTTON_A = 2 BUTTON_B = 1 while True: buttons = pad.get_pressed() if (buttons & BUTTON_START) > 0:
def __init__(self, clk, out, latch, buttons = {0: "b", 1: "a", 2: "start", 3: "select"}, *args, **kwargs): self._pad = GamePadShift(clk, out, latch, *args, **kwargs) self._buttons = buttons