电路图
将其中一个蜂鸣器的正极连接到Arduino的9针,将另一个蜂鸣器的正极连接到Arduino的10针。然后将两个蜂鸣器的底片连接到Arduino的底部。
如何运行程序
首先,在Arduino IDE的帖子末尾粘贴为Arduino提供的代码并上传代码。
然后您需要从Wekinator的快速演练页面下载草图。
下载屏幕上的鼠标控制示例。解压缩并在处理中运行草图。该草图将为Wekinator提供输入。您将需要Wekinator输出的另一个草图。该草图的代码在本文末尾。将其粘贴到处理中并运行它。两个处理输出窗口如下所示:
现在打开Wekinator并进行如下图所示的设置。将输入和输出设置为2.将类型设置为自定义,然后单击“配置”。您还可以查看下面附带的视频以查看过程
当您点击“configure”时,会打开一个新窗口,如下图所示。在该窗口中设置设置,如下图所示。
现在将处理窗口中的绿框拖到左下角,然后点击“随机”。开始录制半秒。
将处理窗口中的绿色框拖到中间顶部,然后单击“randomize”。开始录制半秒。
将处理窗口中的绿框拖到右下角,然后单击“随机化”。之后,开始录制半秒。
然后点击“Train”,然后点击“Run”。现在,当您在处理窗口中拖动绿色框时,Arduino会根据此发出噪音。
尝试使用不同的界面进行试验,甚至尝试使用此图形界面合成器制作音乐。
处理代码(Wekinator输出)
import vsync.*; // Importing the library that will help us in sending and receiving the values from the Arduino
import processing.serial.*; // Importing the serial library
// Below libraries will connect and send, receive the values from wekinator
import oscP5.*;
import netP5.*;
// Creating the instances
OscP5 oscP5;
NetAddress dest;
ValueSender sender;
// These variables will be syncronized with the Arduino and they should be same on the Arduino side.
public int output;
public int output1;
void setup()
{
// Starting the serial communication, the baudrate and the com port should be same as on the Arduino side.
Serial serial = new Serial(this, “COM10”, 19200);
sender = new ValueSender(this, serial);
// Synchronizing the variables as on the Arduino side. The order should be same.
sender.observe(“output”);
sender.observe(“output1”);
// Starting the communication with wekinator. listen on port 12000, return messages on port 6448
oscP5 = new OscP5(this, 12000);
dest = new NetAddress(“127.0.0.1”, 6448);
}
// Recieve OSC messages from Wekinator
void oscEvent(OscMessage theOscMessage) {
if (theOscMessage.checkAddrPattern(“/wek/outputs”) == true) {
// Receiving the output from wekinator
float value = theOscMessage.get(0).floatValue(); // First output
float val = theOscMessage.get(1).floatValue(); // Second output
// Converting the output to int type
output = int(value);
output1 = int(val);
}
}
void draw()
{
// Nothing to be drawn for this example
}
Arduino代码
#include // Including the library that will help us in receiving and sending the values from processing
ValueReceiver《2》 receiver; /*Creating the receiver that will receive up to 2 values.
Put the number of values to synchronize in the brackets */
/* The below two variables will be synchronized in the processing
and they should be same on both sides. */
int output;
int output1;
// Pin connected to buzzer
int buzzer = 9;
int buzzer1 = 10;
int i,j;
void setup()
{
/* Starting the serial communication because we are communicating with the
Arduino through serial. The baudrate should be same as on the processing side. */
Serial.begin(19200);
// Synchronizing the variables with the processing. The variables must be int type.
receiver.observe(output);
receiver.observe(output1);
// Defines the Buzzer pins as output
pinMode(buzzer,OUTPUT);
pinMode(buzzer1,OUTPUT);
}
void loop()
{
// Receiving the output from the processing.
receiver.sync();
// Making the buzzer to beep according to the output from the processing
tone(buzzer1, output);
delay(5);
noTone(buzzer1);
tone(buzzer,output1);
delay(5);
noTone(buzzer);
}
-
Arduino
+关注
关注
187文章
6461浏览量
186570
发布评论请先 登录
相关推荐
评论