Я попробовал перенести тот же код на Raspberry Pi с некоторыми изменениями, специфичными для Pi. Мой код выглядит следующим образом:
Код: Выделить всё
import pygame
import mido
import rtmidi
import time
import RPi.GPIO as GPIO
pygame.init()
BLACK = [0,0,0]
WHITE = [255, 222, 111]
note_list = []
note_list_off = []
outport=mido.open_output()
inport=mido.open_input()
GPIO.setmode(GPIO.BCM)
done = False
GPIO.setup(4,GPIO.OUT)
print("START!")
while done == False:
for msg in inport.iter_pending():
try:
n = msg.note
except:
continue
if msg.velocity>0 and msg.velocity != 64:
print(msg.velocity)
GPIO.output(4,True)
time.sleep(1)
GPIO.output(4,False)
else:
msg=mido.Message('note_off',note=n)
outport.send(msg)
pygame.quit ()
Код: Выделить всё
GPIO.output(4,True)
time.sleep(1)
GPIO.output(4,False)
Код: Выделить всё
print("START!")
Код: Выделить всё
for msg in inport.iter_pending():
lsusb
Код: Выделить всё
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 07cf:6803 Casio Computer Co., Ltd CTK-3500 (MIDI keyboard)
Код: Выделить всё
Dir Device Name
IO hw:3,0,0 CASIO USB-MIDI MIDI 1
Код: Выделить всё
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 28: 'CASIO USB-MIDI' [type=kernel,card=3]
0 'CASIO USB-MIDI MIDI 1'
aseqdump -p 28 при нажатии клавиш с клавиатуры< /p>
Код: Выделить всё
Waiting for data. Press Ctrl+C to end.
Source Event Ch Data
28:0 Note on 0, note 64, velocity 9
28:0 Note on 0, note 60, velocity 27
28:0 Note on 0, note 57, velocity 1
28:0 Note off 0, note 57, velocity 64
28:0 Note on 0, note 60, velocity 30
28:0 Note on 0, note 57, velocity 23
28:0 Note on 0, note 55, velocity 31
28:0 Note off 0, note 55, velocity 64
28:0 Note off 0, note 60, velocity 64
28:0 Note off 0, note 57, velocity 64
28:0 Note on 0, note 55, velocity 29
28:0 Note off 0, note 55, velocity 64
28:0 Note on 0, note 57, velocity 35
Буду благодарен за любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/786 ... spberry-pi