コード例 #1
0
def init():
    global i2c, cap, capSenseNew, LEDs, sounds
    global pygame, soundNames
    i2c = busio.I2C(board.SCL, board.SDA)
    cap = adafruit_mpr121.MPR121(i2c)
    capSenseNew = io.DigitalInOut(board.D4)
    capSenseNew.direction = io.Direction.INPUT
    capSenseNew.pull = io.Pull.UP
    LEDs = []
    LEDpin = [board.D17, board.D18, board.D27, board.D22, board.D23, board.D24]
    for i in range(0, len(LEDpin)):
        led = io.DigitalInOut(LEDpin[i])
        led.direction = io.Direction.OUTPUT
        LEDs.append(led)
    cap.reset()
    # to see what you have
    print("I2C devices at", i2c.scan())
    pygame.mixer.pre_init(44100, -16, 12, 512)
    pygame.init()
    pygame.mixer.music.set_volume(1.0)
    soundNames = [
        "ambi_choir", "bass_voxy_hit_c", "drum_splash_hard",
        "drum_tom_hi_hard", "drum_tom_lo_hard", "drum_snare_hard",
        "bass_voxy_c", "loop_amen_full"
    ]
    sounds = [
        pygame.mixer.Sound("sounds/" + soundNames[i] + ".wav")
        for i in range(0, len(soundNames))
    ]
コード例 #2
0
        def determineIfTouched():

            i2c = busio.I2C(board.SCL, board.SDA)
            mpr121 = adafruit_mpr121.MPR121(i2c)
            trigger = True

            while trigger:

                if mpr121[2].value:
                    if canDispenseTreat():
                        #ScheduleTreats().terminate()
                        time.sleep(1)
                        dispenseTreat()

                        decrementTodaysTreat()
                        playGoodGirl()
                        time.sleep(1)
                        # scheduleTreatsFlask = ScheduleTreats()
                        # thrSchedule = Thread(target= scheduleTreatsFlask.run)
                        # thrSchedule.start()
                    # else:
                    #     playWaitTilTomorrow()
                    #     time.sleep(1)
                    #     print(mpr121[1].value)
                    #     time.sleep(1)
                    #     playWaitTilTomorrow()
                    #     time.sleep(1)
                    #     if trigger:
                    #         playWaitTilTomorrow()
                    #         time.sleep(2)
                    #         trigger = False
                    trigger = False

            return 1
コード例 #3
0
 def __init__(self,pin,api_info,addr=90):
     self.api_info = api_info
     self.pin = pin
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.buffer = bytearray(2)
     self.addr = addr
     mpr121 = adafruit_mpr121.MPR121(self.i2c)
     self.touched = self.read_from_sensor()
コード例 #4
0
def setup_touch_loop():
    i2c = busio.I2C(board.SCL, board.SDA)
    mpr121 = adafruit_mpr121.MPR121(i2c)
    while True:
        for i in range(12):
            if mpr121[i].value:
                function_name = pin_method_mapping[i]
                if function_name:
                    # call function
                    globals()[function_name]()

        time.sleep(0.10)
コード例 #5
0
 def __init__(self):
     pygame.init()
     self.screen = pygame.display.set_mode((640, 400))
     self.screenrect = self.screen.get_rect()
     pygame.display.set_caption("SpaceFruit")
     self.running = True
     self.penguin = Penguin()
     self.asteroid1 = Asteroid()
     self.asteroid2 = Asteroid()
     self.apple = Apple()
     self.coloumn = [self.asteroid1, self.apple, self.asteroid2]
     self.coloumnXpos = 600
     self.downstate = False
     self.asteroidGroup = pygame.sprite.Group(self.asteroid1,
                                              self.asteroid2)
     self.appleGroup = pygame.sprite.Group(self.apple)
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.mpr121 = adafruit_mpr121.MPR121(self.i2c)
     self.gameState = 0
     self.score = 0
     self.upstate = False
コード例 #6
0
def setup_capacitive_hat():

    i2c = busio.I2C(board.SCL, board.SDA)
    # Create MPR121 object.
    cap = adafruit_mpr121.MPR121(i2c)

    #Old method!!!! only here for reference!!
    #Stop the chip to set a new threshold value 0x00 -> ECR
    #cap._i2c_retry(cap._device.write8,0x5E,0x00)

    #I found this threshold works well with medium fruits (like peaches)
    #Change this for your needs
    #cap.set_thresholds(50, 10)

    #I will check if the register are written correctly (debug purposes)
    #tth=cap._i2c_retry(cap._device.readU8,0x41);
    #rth=cap._i2c_retry(cap._device.readU8,0x42);
    #print "Touch TH:" + str(tth) + "Release TH: " +str(rth)

    #Start again the ic
    #cap._i2c_retry(cap._device.write8,0x5E,0x8F)

    #New method:
    #in new circuit python this is provided but not tested!:
    #app[N].threshold=XX
    #app[N].release_threshold=XX

    #example usage:
    #for i in range(12):
    #	cap[i].threshold=XX
    #	cap[i].release_threshold=XX

    # XX correspond to a 1 byte number (0-255 value)
    # Acording to the datasheet a recommend value is: 4 - 16 for touched (P. 13 of datasheet)
    # In the old code, the value 50 for release and 10 for touched is used.

    return cap
コード例 #7
0
    def activate(self):
        assert self.params['address']
        assert self.params['bus']
        if 'name' in self.params:
            self.name = self.params['name'] + ' %i:%s' % (
                self.params['bus'], hex(self.params['address']))
        if not 'driver' in self.params.keys(): self.params['driver'] = None

        if not 'channel_names' in self.config:
            self.config['channel_names'] = ['Ch%i' % i for i in range(12)]
        self.params['n_channels'] = len(self.config['channel_names'])

        self.params['raw_units'] = [''] * self.params['n_channels']
        self.config['eng_units'] = [''] * self.params['n_channels']
        self.config['scale'] = np.ones(self.params['n_channels'], )
        self.config['offset'] = np.zeros(self.params['n_channels'], )
        if ('untitled' in self.name.lower()) or (self.name == ''):
            self.name = 'MPR121 capacitative touch sensor I2C %i:%s' % (
                self.params['bus'], self.params['address'])

        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.dev = adafruit_mpr121.MPR121(self.i2c)

        return
コード例 #8
0
ファイル: mpr121_piano.py プロジェクト: ahowell13/CircuitPy
    349,  # Input 3 = middle F
    392,  # Input 4 = middle G
    440,  # Input 5 = middle A
    493,  # Input 6 = middle B
    0,  # Input 7 = nothing (set to a frequency in hertz!)
    0,  # Input 8
    0,  # Input 9
    0,  # Input 10
    0
]  # Input 11

# Create I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Create MPR121 class.
mpr121 = adafruit_mpr121.MPR121(i2c)
# Note you can optionally change the address of the device:
#mpr121 = adafruit_mpr121.MPR121(i2c, address=0x91)

#pylint: disable-msg=no-member
# Setup buzzer PWM output.
buzzer = pulseio.PWMOut(BUZZER_PIN,
                        duty_cycle=TONE_OFF_DUTY,
                        frequency=440,
                        variable_frequency=True)
#pylint: disable-msg=no-member

last_note = None
while True:
    # Get touched state for all pins
    touched = mpr121.touched_pins
コード例 #9
0
ファイル: light_touch.py プロジェクト: cega-/smarmirror
##import Adafruit_MPR121.MPR121 as MPR121
# Import MPR121 module.
import adafruit_mpr121 as MPR121
import RPi.GPIO as GPIO

# GPIO_22 Relay 2
# GPIO_27 Relay 1

print('Adafruit MPR121 Capacitive Touch Sensor Test')

# Create MPR121 instance.
##cap = MPR121.MPR121()
# Create I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

cap = MPR121.MPR121(i2c)

#if not cap.begin():
#    print('Error initializing MPR121.  Check your wiring!')
#    sys.exit(1)

# Main loop to print a message every time a pin is touched.
print('Press Ctrl-C to quit.')
last_touched = cap.touched()
l_press_touch = []
while True:
    current_touched = cap.touched()
    # Check each pin's last and current state to see if it was pressed or released.
    for i in range(12):
        # Each pin is represented by a bit in the touched value.  A value of 1
        # means the pin is being touched, and 0 means it is not being touched.
コード例 #10
0
ファイル: PumpCalibration.py プロジェクト: nijie321/PeerPub
def pump_calibration(step_size, fname):
    old_step = step_size
    step = step_size
    # command = input("Please scan the ") 
    act_count = 0
    i2c = busio.I2C(board.SCL, board.SDA)
    mpr121 = adafruit_mpr121.MPR121(i2c)

    mover = PumpMove()
    forwardbtn = Button("GPIO5")
    backwardbtn = Button("GPIO27")

    BACKWARD_LIMIT_BTN = "GPIO23"
    BACKWARD_LIMIT = DigitalInputDevice(BACKWARD_LIMIT_BTN)

    def forward():
        while forwardbtn.value == 1:
            mover.move("forward")

    def backward():
        while BACKWARD_LIMIT.value != 1:
            mover.move("backward")

    forwardbtn.when_pressed = forward
    backwardbtn.when_pressed = backward

    print("current step size = " + str(step_size)) 
    print("please prepare to measure the solution.")

    while True:
        time.sleep(0.050)
        act = mpr121.touched_pins[1]

        if act:
            if act_count % 5 == 0:
                for i in range(5):
                    mover.move("forward", step)

            act_count += 1
            print("count" + str(act_count))
            if act_count == 15:
                response = input("please enter the amount measured (numeric value) or scan the command id again to exit: ").strip()
                # if the same command RFID is scanned again, exit the while loop
                if response[-2:] == '6b' or response[-2:] == '8e' or response[-2:] == 'ba':
                    break
                else:
                    try:
                        response = int(response)
                    except ValueError:
                        response = int(input("please re-enter the amount measured: ").strip())

                avg_measured_value = response / 3
                print("average value: {}".format(avg_measured_value))
                
                if (avg_measured_value < (300-10) or avg_measured_value > (300+10)):
                    # update step size
                    print("previous step: {}".format(step))
                    step = math.ceil( (step / (avg_measured_value / 5)) *60  )
                    
                    print("modified step: {}".format(step))
                    print("Touch spout to measure again")
                
                act_count = 0

    del(mover)

    date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    record = "{}\t"*3

    ids = IDS()
    # print out the old/new steps after the calibration
    print("old step size: {}".format(old_step))
    print("new step size: {}".format(step))

    # overwrite the old step size in 'peerpub_config.json' file
    ids.change_step(step)

    f_specifiers = ""
    file_path = file_dir.format(fname)
    print("Update stepsize in " +fname)
    if os.path.isfile(file_path):
        f_specifiers = "a"
    else:
        f_specifiers = "a"

    with open(file_path, f_specifiers) as f:
        f.write((record+"\n").format(date, old_step, step))
コード例 #11
0
ファイル: tomatosquish.py プロジェクト: Kriegerbr/pi-py-fun
import time
import board
import busio
import os
from playsound import playsound

# Import MPR121 module.
import adafruit_mpr121

# Create I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Create MPR121 object.
mpr121 = adafruit_mpr121.MPR121(i2c, 0x5a)
# Note you can optionally change the address of the device:
# mpr121 = adafruit_mpr121.MPR121(i2c, address=0x91)

# Loop forever testing each input and printing when they're touched.
while True:
    # Loop through all 12 inputs (0-11).
    for i in range(12):
        # Call is_touched and pass it then number of the input.  If it's touched
        # it will return True, otherwise it will return False.
        if mpr121[0].value:
            print("Input {} touched!".format(i))
            print("it found it!")
            #playsound("/home/pi/300.wav")
            os.system("aplay /home/pi/squish.wav")
    time.sleep(0.25)  # Small delay to keep from spamming output messages.
コード例 #12
0
ファイル: input.py プロジェクト: directive0/picorderOS
        # setup our 3 control buttons
        GPIO.setup(pins[0], GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(pins[1], GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(pins[2], GPIO.IN, pull_up_down=GPIO.PUD_UP)

# set up requirements for capacitive buttons using an mpr121
if configure.input_cap_mpr121:
    # if using the capacitive touch board from adafruit we import that library
    import adafruit_mpr121
    import busio

    # initiate I2C bus.
    i2c = busio.I2C(configure.PIN_SCL, configure.PIN_SDA)

    # Create MPR121 object. Address can be 5A or 5B (proto uses 5A)
    mpr121 = adafruit_mpr121.MPR121(i2c, address=0x5A)

    # initializes each input
    for i in range(3):
        test = adafruit_mpr121.MPR121_Channel(mpr121, i)
        test.threshold = threshold
        test.release_threshold = release_threshold

if configure.input_cap1208:

    import RPi.GPIO as GPIO

    GPIO.setmode(GPIO.BCM)

    interrupt_pin = 0
    GPIO.setup(interrupt_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
コード例 #13
0
import _thread

print(board.SCL)
print(board.SDA)

i2c = busio.I2C(board.SCL, board.SDA)

ON_PRESS = "on_press"
ON_RELEASE = "on_release"
TRIGGER_BEHAVIOR = ON_RELEASE

SENSOR_ADDRESSES = [0x5A, 0x5B, 0x5C]
# SENSOR_ADDRESSES = [0x5A, 0x5B]
# SENSOR_ADDRESSES = [0x5A]
mpr121s = [
    adafruit_mpr121.MPR121(i2c, address=address)
    for address in SENSOR_ADDRESSES
]
SENSORS_PER_CHIP = 12
SEMITONES_PER_OCTAVE = 12
SENSOR_COUNT = len(mpr121s) * SENSORS_PER_CHIP
TICK_SECONDS = 0.01

print("Available MIDI outputs:")
print(mido.get_output_names())
port_name = mido.get_output_names()[2]
print("Using port:", port_name)
port = mido.open_output(port_name)
port.panic()
port.send(mido.Message('program_change', program=24))
コード例 #14
0
def init():
    global i2c, cap, capSenseNew, LEDs, sounds
    global pygame, soundNames, playing, contPlay
    global pad, sWide, sHigh, screen, backCol, seqNotes
    global padCo, dLED, sLED, black, font, ccol
    global choiceRect, yes, no, choices, incRect
    global plus, minus, bpm, stepTime, playback
    global nextStep, recording, stepCount, savePos
    global bank, recordedBank, stopping
    i2c = busio.I2C(board.SCL, board.SDA)
    cap = adafruit_mpr121.MPR121(i2c)
    capSenseNew = io.DigitalInOut(board.D4)
    capSenseNew.direction = io.Direction.INPUT
    capSenseNew.pull = io.Pull.UP
    LEDs = []
    LEDpin = [board.D17, board.D18, board.D27, board.D22, board.D23, board.D24]
    for i in range(0, len(LEDpin)):
        led = io.DigitalInOut(LEDpin[i])
        led.direction = io.Direction.OUTPUT
        LEDs.append(led)
    cap.reset()
    i2c.scan()  # this is needed
    # Initialise Pygame system
    pygame.mixer.quit()
    pygame.mixer.pre_init(44100, -16, 2, 512)
    pygame.init()
    pygame.mixer.music.set_volume(1.0)
    pygame.mixer.set_num_channels(20)
    pygame.init()
    pygame.display.set_caption("Hex-A-Pad -> Sample Sequencer")
    os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
    pygame.event.set_allowed(None)
    pygame.event.set_allowed([
        pygame.KEYDOWN, pygame.QUIT, pygame.MOUSEBUTTONDOWN,
        pygame.MOUSEBUTTONUP
    ])
    sWide = 430
    sHigh = 520
    padCo = (sWide // 2 - 100, 48)  # top of screen
    screen = pygame.display.set_mode([sWide, sHigh], 0, 32)
    # Load graphics
    pad = pygame.image.load("images/pad.png").convert_alpha()
    backCol = (160, 160, 160)
    black = (0, 0, 0)
    ccol = [black, (255, 0, 70), (0, 255, 0), (255, 222, 0)]
    x = [38, 69, 129, 161, 131, 68, 62, 136]
    y = [110, 58, 56, 109, 163, 163, 78, 77]
    dLED = []
    for i in range(0, 8):
        dLED.append((x[i] + padCo[0], y[i] + padCo[1]))
    sLED = []
    s = math.radians(22.5)
    for i in range(0, 16):
        sLED.append((int(138 * math.cos(i * s) + (sWide // 2)),
                     int(138 * math.sin(i * s) + padCo[1] + 113)))
    choiceRect = [pygame.Rect((0, 0), (15, 15))] * 7
    for i in range(0, 5):
        ost = 0
        if i > 1: ost = 30
        choiceRect[i] = pygame.Rect((155, ost + 344 + i * 30), (15, 15))
    choiceRect[5] = pygame.Rect((355, 344), (15, 15))
    choiceRect[6] = pygame.Rect((355, 374), (15, 15))
    incRect = [pygame.Rect((240, 402), (15, 15))] * 4
    incRect[1] = pygame.Rect((260, 402), (15, 15))
    incRect[2] = pygame.Rect((353, 402), (15, 15))
    incRect[3] = pygame.Rect((373, 402), (15, 15))
    no = pygame.image.load("images/0.png").convert_alpha()
    yes = pygame.image.load("images/1.png").convert_alpha()
    plus = pygame.image.load("images/plus.png").convert_alpha()
    minus = pygame.image.load("images/minus.png").convert_alpha()
    choices = [False] * 7
    presetC = [5, 2, 6]  # power up choices
    for i in range(0, len(presetC)):
        choices[presetC[i]] = True
    # Load Sounds three banks
    soundNames1 = [
        "tabla_ghe4", "bass_voxy_hit_c", "drum_splash_hard",
        "drum_tom_hi_hard", "drum_tom_lo_hard", "drum_snare_hard",
        "bass_voxy_c", "loop_amen_full"
    ]
    sounds1 = [
        pygame.mixer.Sound("sounds/" + soundNames1[i] + ".wav")
        for i in range(0, len(soundNames1))
    ]
    soundNames2 = [
        "Sax_a", "Sax_c", "Sax_d", "Sax_e", "Sax_g", "Sax_a2", "Sax_c2",
        "Sax_d2"
    ]
    sounds2 = [
        pygame.mixer.Sound("sounds/" + soundNames2[i] + ".wav")
        for i in range(0, len(soundNames2))
    ]
    soundNames3 = ["K_a", "K_c", "K_d", "K_e", "K_g", "K_a2", "K_c2", "K_d2"]
    sounds3 = [
        pygame.mixer.Sound("sounds/" + soundNames3[i] + ".wav")
        for i in range(0, len(soundNames3))
    ]
    sounds = [sounds1, sounds2, sounds3]
    font = pygame.font.Font(None, 24)
    playing = [pygame.mixer.Channel(0)] * 8
    contPlay = [False, False]
    playback = False
    recording = False
    nextStep = time.time()
    stepCount = -1
    savePos = 0
    bank = 0
    seqNotes = []
    recordedBank = 0
    stopping = False
    for i in range(0, 16):
        seqNotes.append([-1, -1, -1, -1, -1, -1])
    bpm = 200
    stepTime = 1 / (bpm / 60)
コード例 #15
0
 def __init__(self):
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.mpr121 = adafruit_mpr121.MPR121(i2c)
     self._running = True
コード例 #16
0
def init():
    global i2c, cap, capSenseNew, LEDs, sounds
    global pygame, soundNames, playing, contPlay
    global pad, sWide, sHigh, screen, backCol, seqNotes
    global padCo, dLED, sLED, black, font, ccol
    global choiceRect, yes, no, choices, incRect
    global plus, minus, bpm, stepTime, playback
    global nextStep, recording, stepCount, savePos
    global bank, recordedBank, mMap, recordedMap
    global mChan, mInst, mBank, MIDIplaying, midiout
    global noteDuration, seqMIDINotes, midiRecording
    global mInstName

    i2c = busio.I2C(board.SCL, board.SDA)
    cap = adafruit_mpr121.MPR121(i2c)
    capSenseNew = io.DigitalInOut(board.D4)
    capSenseNew.direction = io.Direction.INPUT
    capSenseNew.pull = io.Pull.UP
    LEDs = []
    LEDpin = [board.D17, board.D18, board.D27, board.D22, board.D23, board.D24]
    for i in range(0, len(LEDpin)):
        led = io.DigitalInOut(LEDpin[i])
        led.direction = io.Direction.OUTPUT
        LEDs.append(led)
    cap.reset()
    i2c.scan()  # this is needed
    # Initialise Pygame system
    pygame.mixer.quit()
    pygame.mixer.pre_init(44100, -16, 2, 512)
    pygame.init()
    pygame.mixer.music.set_volume(1.0)
    pygame.mixer.set_num_channels(20)
    pygame.init()
    pygame.display.set_caption("Hex-A-Pad -> Sound & MIDI Sequencer")
    os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
    pygame.event.set_allowed(None)
    pygame.event.set_allowed([
        pygame.KEYDOWN, pygame.QUIT, pygame.MOUSEBUTTONDOWN,
        pygame.MOUSEBUTTONUP
    ])
    sWide = 430
    sHigh = 700
    padCo = (sWide // 2 - 100, 48)  # top of screen
    screen = pygame.display.set_mode([sWide, sHigh], 0, 32)
    # Load graphics
    pad = pygame.image.load("images/pad.png").convert_alpha()
    backCol = (160, 160, 160)
    black = (0, 0, 0)
    ccol = [black, (255, 0, 70), (0, 255, 0), (255, 222, 0)]
    x = [38, 69, 129, 161, 131, 68, 62, 136]
    y = [110, 58, 56, 109, 163, 163, 78, 77]
    dLED = []
    for i in range(0, 8):
        dLED.append((x[i] + padCo[0], y[i] + padCo[1]))
    sLED = []
    s = math.radians(22.5)
    for i in range(0, 16):
        sLED.append((int(138 * math.cos(i * s) + (sWide // 2)),
                     int(138 * math.sin(i * s) + padCo[1] + 113)))
    choiceRect = [pygame.Rect((0, 0), (15, 15))] * 19
    for i in range(0, 7):
        for j in range(0, 2):
            if not (i * 2 + j == 4 or i * 2 + j == 5):
                choiceRect[i * 2 + j] = pygame.Rect(
                    (155 + j * 200, 344 + i * 30), (15, 15))
    for i in range(14, 19):
        choiceRect[i] = pygame.Rect((355, 134 + i * 30), (15, 15))
    incRect = [pygame.Rect((240, 402), (15, 15))] * 4
    incRect[1] = pygame.Rect((260, 402), (15, 15))
    incRect[2] = pygame.Rect((353, 402), (15, 15))
    incRect[3] = pygame.Rect((373, 402), (15, 15))
    no = pygame.image.load("images/0.png").convert_alpha()
    yes = pygame.image.load("images/1.png").convert_alpha()
    plus = pygame.image.load("images/plus.png").convert_alpha()
    minus = pygame.image.load("images/minus.png").convert_alpha()
    choices = [False] * 19
    presetC = [1, 3, 4, 7, 8, 9, 17]
    for i in range(0, len(presetC)):
        choices[presetC[i]] = True
    # Load Sounds three banks
    soundNames1 = [
        "tabla_ghe4", "bass_voxy_hit_c", "drum_splash_hard",
        "drum_tom_hi_hard", "drum_tom_lo_hard", "drum_snare_hard",
        "bass_voxy_c", "loop_amen_full"
    ]
    sounds1 = [
        pygame.mixer.Sound("sounds/" + soundNames1[i] + ".wav")
        for i in range(0, len(soundNames1))
    ]
    soundNames2 = [
        "Sax_a", "Sax_c", "Sax_d", "Sax_e", "Sax_g", "Sax_a2", "Sax_c2",
        "Sax_d2"
    ]
    sounds2 = [
        pygame.mixer.Sound("sounds/" + soundNames2[i] + ".wav")
        for i in range(0, len(soundNames2))
    ]
    soundNames3 = ["K_a", "K_c", "K_d", "K_e", "K_g", "K_a2", "K_c2", "K_d2"]
    sounds3 = [
        pygame.mixer.Sound("sounds/" + soundNames3[i] + ".wav")
        for i in range(0, len(soundNames3))
    ]
    sounds = [sounds1, sounds2, sounds3]
    # Load six banks of MIDI mapping
    mMap1 = [(57, 80), (60, 80), (62, 80), (64, 80), (67, 80), (69, 80),
             (72, 80), (74, 80)]
    mMap2 = [(45, 80), (48, 80), (50, 80), (52, 80), (55, 80), (57, 80),
             (60, 80), (62, 80)]
    mMap3 = [(57, 80), (60, 80), (62, 80), (64, 80), (67, 80), (69, 80),
             (72, 80), (74, 80)]
    mMap4 = [(57, 80), (60, 80), (62, 80), (64, 80), (67, 80), (69, 80),
             (72, 80), (74, 80)]
    mMap5 = [(69, 80), (72, 80), (74, 80), (76, 80), (79, 80), (81, 80),
             (84, 80), (86, 80)]
    mMap6 = [(55, 127), (58, 127), (60, 127), (61, 127), (65, 127), (66, 127),
             (81, 127), (71, 127)]
    mMap = [mMap1, mMap2, mMap3, mMap4, mMap5, mMap6]
    mChan = [0, 1, 2, 3, 4, 9]  # MIDI channels for each mapping
    mInstName = [
        "Bells", "Organ", "Harpsichord", "Choir", "Pan Flute", "Percussion"
    ]
    mInst = [14, 19, 6, 52, 75, 0]
    mBank = 0  # current mapping to use
    MIDIplaying = [(0.0, 0, -1)] * 8  # time started, channel, note
    noteDuration = 0.9  # time a triggered note lasts
    midiout = rtmidi.MidiOut()
    initMIDI()
    font = pygame.font.Font(None, 24)
    playing = [pygame.mixer.Channel(0)] * 8
    contPlay = [False, False]
    playback = False
    recording = False
    nextStep = time.time()
    stepCount = -1
    savePos = 0
    bank = 0
    seqNotes = []
    recordedBank = 0
    for i in range(0, 16):
        seqNotes.append([-1, -1, -1, -1, -1, -1])
    seqMIDINotes = []
    st = (-1, (-1, -1))
    for i in range(0, 16):
        seqMIDINotes.append([st, st, st, st, st, st])
    midiRecording = True
    bpm = 200
    stepTime = 1 / (bpm / 60)
コード例 #17
0
 task_name = input('Enter the task name: ')
 task_settings = SPT.task_settings(task_name)
 try:
     #reads from task json file loaded
     tag_in_range_pin = task_settings.task_config['tag_in_range_pin']
     solenoid_pin_LW = task_settings.task_config['solenoid_pin_LW']
     solenoid_pin_LS = task_settings.task_config['solenoid_pin_LS']
     solenoid_pin_RW = task_settings.task_config['solenoid_pin_RW']
     solenoid_pin_RS = task_settings.task_config['solenoid_pin_RS']
     buzzer_pin = task_settings.task_config['buzzer_pin']
     vid_folder = task_settings.task_config['vid_folder']
     hours = task_settings.task_config['hours']
     #starts the rest of the hardware
     serialPort = '/dev/ttyUSB0'
     i2c = busio.I2C(board.SCL, board.SDA)
     lickdector = mpr121.MPR121(i2c, address=0x5A)
     solenoid_RW = SPT.solenoid(solenoid_pin_RW)
     solenoid_RS = SPT.solenoid(solenoid_pin_RS)
     solenoid_LW = SPT.solenoid(solenoid_pin_LS)
     solenoid_LS = SPT.solenoid(solenoid_pin_LW)
     globalReader = None
     globalTag = 0
     vs = SPT.piVideoStream(folder=vid_folder)
     vs.cam_setup()
     #may need a better function for the buzzer
     buzzer = SPT.buzzer(buzzer_pin, 1500, 50)
 except Exception as e:
     print(e)
     print(
         'Error in iniatializing hardware, please check wiring and task settings'
     )