12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import sys
- from pygame import mixer
- import time
- import digitalio
- import board
- import adafruit_matrixkeypad
- import pygame
- import digitalio
- import board
- import RPi.GPIO as GPIO
- from time import sleep
-
- GPIO.setmode(GPIO.BCM)
-
- GPIO.setup(47, GPIO.OUT)
- cols = [digitalio.DigitalInOut(x) for x in (board.D21, board.D20, board.D16, board.D12)]
- rows = [digitalio.DigitalInOut(x) for x in (board.D26, board.D13, board.D6, board.D5)]
-
- keys = ((15, 14, 13, 12),
- (11, 10, 9, 8),
- (7, 6, 5, 4),
- (3, 2, 1, 0))
-
-
- keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
-
- pygame.init()
- mixer.init()
- mixer.set_num_channels(32)
- done = False
- clock = pygame.time.Clock()
- TIMER = pygame.USEREVENT + 1
- playhead = 0
-
- timer = pygame.time.get_ticks
- start = now = timer()
-
- cs_pin = digitalio.DigitalInOut(board.CE0)
- dc_pin = digitalio.DigitalInOut(board.D25)
- reset_pin = None
- BAUDRATE = 64000000
-
- spi = board.SPI()
-
- class Prog:
- def __init__(self):
- self.keys = []
- self.keyState = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
-
-
- class SoundSlot:
- def __init__(self, file, obj_id, o):
- self.file = file
-
- def Execute(self):
- self.keys = keypad.pressed_keys
- self.update_keys()
- #self.FSM.Execute()
-
- def update_keys(self):
- _id = 0
- for k in self.keyState:
- if k == 0:
- if _id in self.keys:
- self.keyState[_id] = 1
- print('key on ', _id)
-
- elif k == 1:
- if _id in self.keys:
- self.keyState[_id] = 2
- else:
- self.keyState[_id] = 3
- elif k == 2:
- if _id in self.keys:
- self.keyState[_id] = 2
- else:
- self.keyState[_id] = 3
- else:
- self.keyState[_id] = 0
- _id += 1
-
-
- p = Prog()
-
- while not done:
- p.Execute()
- if pygame.event.get(pygame.USEREVENT + 1):
-
- p.playhead += 1
-
- clock.tick_busy_loop()
- #print(clock.get_fps())
-
- pygame.quit()
|