電路圖
將其中一個蜂鳴器的正極連接到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
+關注
關注
188文章
6491瀏覽量
190096
發布評論請先 登錄
精密空調—精密空調噪音擾人?看降噪音妙招!

評論