设置arduino board
这个项目使用连接到arduino uno的五个按钮。使用arduino为按钮建立连接,如下图所示。
项目草图
在输入端,我们将有一个arduino草图和一个processing草图。 arduino草图将读取五个按钮的状态,并通过串行通信将其转发到processing。 processing sketch将接收此数据,并通过osc(开放式声音控制)协议将其转发给wekinator。
arduino sketch
#define buttonpin1 6
#define buttonpin2 5
#define buttonpin3 4
#define buttonpin4 3
#define buttonpin5 2
int inbyte = 0; // incoming serial byte
// the setup function runs once when you press reset or power the board
void setup() {
serial.begin(115200);
pinmode(buttonpin1, input);
pinmode(buttonpin2, input);
pinmode(buttonpin3, input);
pinmode(buttonpin4, input);
pinmode(buttonpin5, input);
establishcontact(); // send a byte to establish contact until receiver
// responds
}
// the loop function runs over and over again forever
void loop() {
// if we get a valid byte, read button pins:
if (serial.available() 》 0) {
// get incoming byte:
inbyte = serial.read();
// read the state of the pushbuttons:
int buttonstate1 = digitalread(buttonpin1);
int buttonstate2 = digitalread(buttonpin2);
int buttonstate3 = digitalread(buttonpin3);
int buttonstate4 = digitalread(buttonpin4);
int buttonstate5 = digitalread(buttonpin5);
serial.write(buttonstate1);
serial.write(buttonstate2);
serial.write(buttonstate3);
serial.write(buttonstate4);
serial.write(buttonstate5);
}
}
void establishcontact() {
while (serial.available() 《= 0) {
serial.print(‘a’); // send a capital a
delay(300);
}
}
处理草图
import processing.serial.*;
import oscp5.*;
import netp5.*;
oscp5 oscp5;
netaddress dest;
serial myport; // the serial port
int[] serialinarray = new int[5]; // where we‘ll put what we receive
int serialcount = 0; // a count of how many bytes we receive
int button1, button2, button3, button4, button5;
boolean firstcontact = false; // whether we’ve heard from the microcontroller
void setup() {
size(256, 256); // stage size
nostroke(); // no border on the next thing drawn
// print a list of the serial ports, for debugging purposes:
println(serial.list());
// i know that the first port in the serial list on my mac
// is always my ftdi adaptor, so i open serial.list()[0]。
// on windows machines, this generally opens com1.
// open whatever port is the one you‘re using.
string portname = serial.list()[0];
myport = new serial(this, portname, 115200);
/* start oscp5, sending messages at port 9000 */
oscp5 = new oscp5(this,9000);
dest = new netaddress(“127.0.0.1”,6448);
}
void draw() {
//send the osc message
sendosc();
}
void serialevent(serial myport) {
// read a byte from the serial port:
int inbyte = myport.read();
// if this is the first byte received, and it’s an a,
// clear the serial buffer and note that you‘ve
// had first contact from the microcontroller.
// otherwise, add the incoming byte to the array:
if (firstcontact == false) {
if (inbyte == ’a‘) {
myport.clear(); // clear the serial port buffer
firstcontact = true; // you’ve had first contact from the microcontroller
myport.write(‘a’); // ask for more
}
}
else {
// add the latest byte from the serial port to array:
serialinarray[serialcount] = inbyte;
serialcount++;
// if we have 3 bytes:
if (serialcount 》 4 ) {
button1 = serialinarray[0];
button2 = serialinarray[1];
button3 = serialinarray[2];
button4 = serialinarray[3];
button5 = serialinarray[4];
// print the values (for debugging purposes only):
println(button1 + “&” + button2 + “&” + button3 + “&” + button4 + “&” + button5);
// send a capital a to request new sensor readings:
myport.write(‘a’);
// reset serialcount:
serialcount = 0;
}
}
}
void sendosc() {
oscmessage msg = new oscmessage(“/wek/inputs”);
msg.add((float)button1);
msg.add((float)button2);
msg.add((float)button3);
msg.add((float)button4);
msg.add((float)button5);
oscp5.send(msg, dest);
}
设置chuck
在输出端,我们可以使用chuck从wekinator接收五个连续输出,并根据这些输出发出声音。
下载您正在使用的操作系统的fm synthesis示例。
现在打开终端并转到您放置它的目录并输入以下行:
chuck fmsynth_5continousoutputs.ck
chuck将开始收听wekinator的输出并接收输出,它将改变声音的音高。
设置wekinator
现在打开wekinator并对设置进行以下调整:
将输入设置为5并输出为5
选择输出键入到所有连续
wekinator将从processing接收五个输入,并在训练后将向chuck发送五个不同的输出。从那里,chuck将根据wekinator输出产生不同的声音。
点击 下一步 按钮,您将看到此窗口:
按第一个按钮,然后单击 随机化 。开始录制一秒钟,它将记录一些样本。
按第二个按钮,然后单击 随机化 的。然后记录一秒。
同样,记录其他三个按钮的样本。
记录五个样本后,单击在 火车 上训练wekinator。然后单击 运行 。现在当您按下按钮时,程序将根据您提供的输入发出声音。
相关项目
如何构建arduino演讲者几分钟播放音乐
新智能型土壤养分检测仪多少钱一台?好用吗?
碳化硅功率晶体的发展方向及驱动电压限制
一加8 Pro保护壳曝光 后置竖排三摄且未保留3.5mm耳机孔
麒麟960与高通骁龙821之间有着怎样的差距?
新能源汽车电源之锂硫电池利弊谈
如何使用Arduino Processing和Wekinator按钮更改声音播放器的音高
内置T6963C液晶显示模块在MSP430中的控制技术
联发科获多家手机 / 平板 / 笔记本厂商 Wi-Fi 7订单
2022年有什么蓝牙耳机?2022年最好的蓝牙耳机排行榜
曼富图越野者登山套装评测 最适合爱好登山的摄影用户使用
AI将终结乔布斯时代 荣耀手机将全面拥抱AI
如何在不增加额外参数量的前提下把模型的表达能力挖掘到极致
IBM智能决策系统助您安定乾坤
粗纤维测定仪的作用是什么,它的功能都有哪些
科创板新光光电总经理助理付经武介绍、履历信息
人脸识别技术在无人机上开发出新技术,及社会反映
工业互联网如何改变企业的商业模式?
麒麟芯片产品用于人工智能场景的 AI 芯片昇腾系列
柔性电路板焊接方法操作与需注意的问题
淄博移动联手华为在禾丰生态无人农场开通了首个5G站点