美文网首页其他科技创新
树莓派(2)theremin 制作

树莓派(2)theremin 制作

作者: mouse0531 | 来源:发表于2019-11-24 13:27 被阅读0次

1 软件安装

sudo apt update

sudo apt upgrade -y

安装Python依赖文件

sudo pip3 install python-osc

如果安装不成功,则将pip3--> pip

2 模拟泰勒明琴的过程

需要:

超声波距离传感器


超声波距离传感器

Python
当前流行的人工智能语言


Python

sonic-pi
树莓派的一款音乐制作程序


sonic-pi

3背景:

泰勒明琴是一款特殊的乐器,通过不接触形式的演奏方式来产生音乐,但是泰勒明琴的制作过程十分复杂,内部结构多样,价格昂贵。我们的项目是通过使用Python代码与超声波传感器在树莓派系统上利用sonic-pi模拟泰勒明琴的演奏过程。

泰勒明琴

4 .接线图表

名称 接线
GND GND
Trig Pin4
Echo Pin17
VCC VCC
图纸

5 Python代码

使用 Python代码连接超声波传感器

#导入超声波传感器的库
from gpiozero import DistanceSensor
from time import sleep

sensor = DistanceSensor(echo=17, trigger=4)

while True:
    print(sensor.distance)
    sleep(1)
result

6.sonic-pi的连接

安装 sonic-pi

sudo apt-get install sonic-pi

打开

live_loop :listen do
    use_real_time
    note = sync "/osc/play_this"
    play note[0]
end

PYTHON连接 sonic-pi代码:

from gpiozero import DistanceSensor
from time import sleep

from pythonosc import osc_message_builder
from pythonosc import udp_client

sensor = DistanceSensor(echo=17, trigger=4)
sender = udp_client.SimpleUDPClient('127.0.0.1', 4559)

while True:
    pitch = round(sensor.distance * 100 + 30)
    sender.send_message('/play_this', pitch)
    sleep(0.1)

相关文章

网友评论

    本文标题:树莓派(2)theremin 制作

    本文链接:https://www.haomeiwen.com/subject/thbqwctx.html