M5Stack Unit Synth - eiichiromomma/CVMLAB GitHub Wiki
M5Stack) Unit-Synth
(Unit-SynthでMIDIプログラミング。
落とし穴
UIFow2だといきなり動かない(202406)
from unit import SYNTHUnit
と書かれるが
from unit.synth import SYNTHUnit
が正解。
UARTはUnit-SynthのIN
とTXD2(17)
を繋ぐ。Core2ならG14(右側上から8番目)。Unit-SynthのNCは使わないのでピンのショートが気になるならRDX2に刺しておく。
ソース(UIFlow2)
import os, sys, io
import M5
from M5 import *
from unit.synth import SYNTHUnit
import time
synth_0 = None
def setup():
global synth_0
M5.begin()
Widgets.fillScreen(0x222222)
synth_0 = SYNTHUnit(port=(16, 17), port_id=1)
synth_0.set_instrument(127, 0, 5)
synth_0.set_master_volume(64)
oto = [65,65,69,71,69,71,65,65,65,69,71,69,71,69,71,72,72,71,69,69,65,64,69,65,64,65,64,62,64]
nagasa = [1000,500,500,500,500,1000,500,500,500,500,500,500,1000,500,500,500,500,500,250,250,500,500,500,500,1000,500,500,1000,1000]
def loop():
global synth_0
M5.update()
for (t,L) in zip(oto,nagasa):
synth_0.set_note_on(0,t,127)
time.sleep_ms(L)
synth_0.set_note_off(0,0)
if __name__ == '__main__':
try:
setup()
while True:
loop()
except (Exception, KeyboardInterrupt) as e:
try:
from utility import print_error_msg
print_error_msg(e)
except ImportError:
print("please update to latest firmware")