連接RGB LED的最長腳到Arduino。通過220歐姆電阻將其他支路連接到Arduino的引腳9,10和11,如下面的電路圖所示。
如何運行程序
首先,粘貼在Arduino IDE中本文末尾為Arduino提供的代碼并上傳代碼。
然后,您需要從Wekinator的示例頁面下載草圖。
下載MFCC的可執行文件(mel頻率倒頻譜系數)。我有一個64位操作系統,所以我從那里下載了“win64”。
下載后,解壓縮并運行“.exe”文件。它將如下所示。現在您需要一個麥克風來為Wekinator提供輸入。如果您已連接外接麥克風,請確保在計算機的聲音設置中選擇它。
您將需要另一個草圖(“輸出草圖”) )從Wekinator獲得輸出。該草圖在本文末尾給出。將其粘貼到新的處理窗口并運行草圖。
現在打開Wekinator并進行如下圖所示的設置。將輸入設置為13,將輸出設置為1.將類型設置為“所有動態時間扭曲”,使用3種手勢類型,然后單擊“下一步”。
現在按住output_1前面的“+”按鈕并說“紅色”。
然后按住output_2前面的“+”按鈕并說“綠色”。
然后按住output_3前面的“+”按鈕并說“藍色”。
之后,單擊“Train”,然后單擊“Run”。現在,RGB LED的顏色將根據您說的顏色名稱而改變。
Arduino代碼
#include //Including the library that will help us in receiving and sending the values from processing
ValueReceiver《1》 receiver; /*Creating the receiver that will receive 1 value.
Put the number of values to synchronize in the brackets */
/* The below variable will be synchronized in the processing
and they should be same on both sides. */
int output;
// Initializing the pins for led‘s
int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
void setup()
{
/* Starting the serial communication because we are communicating with the
Processing through serial. The baudrate should be same as on the processing side. */
Serial.begin(19200);
pinMode(red_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(blue_light_pin, OUTPUT);
// Synchronizing the variable with the processing. The variable must be int type.
receiver.observe(output);
}
void loop()
{
// Receiving the output from the processing.
receiver.sync();
// Matching the received output to light up the RGB LED
if (output == 1)
{
RGB_color(255, 0, 0); // Red
}
else if (output == 2)
{
RGB_color(0, 255, 0); // Green
}
else if (output ==3)
{
RGB_color(0, 0, 255); // Blue
}
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}
處理代碼(輸出草圖)
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;
// This variable will be syncronized with the Arduino and it should be same on the Arduino side.
public int output;
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 variable as on the Arduino side.
sender.observe(“output”);
// 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);
}
//This is called automatically when OSC message is received
void oscEvent(OscMessage theOscMessage) {
if (theOscMessage.checkAddrPattern(“/output_1”)==true)
{
output = 1;
}
else if (theOscMessage.checkAddrPattern(“/output_2”)==true)
{
output = 2;
}
else if (theOscMessage.checkAddrPattern(“/output_3”) == true)
{
output = 3;
}
else
{
}
}
void draw()
{
// Nothing to be drawn for this example
}
-
led
+關注
關注
242文章
23431瀏覽量
664564 -
Arduino
+關注
關注
188文章
6478瀏覽量
188295
發布評論請先 登錄
相關推薦
DLPC150采用I2C控制時,如何控制LED開關?如何控制顯示的顏色?
如何選擇PCB顏色
用TPA3001做音頻信號的功放,輸出的聲音很沙啞是怎么回事?
請問TAS5706如何用硬件控制I2C?
Tas2555聲音通訊已實現,音量控制用這個寄存器Speaker Control Register實現嗎?
多個TLV320AIC3254用一路I2C總線對其配置可行嗎?
如何用5509A產生一個白噪聲,經AIC23播放出來然后再用AIC23采集這個聲音?
探秘PCB板顏色:從外觀到內涵的多重解讀
怎樣用自己的電腦遠程公司的電腦

評論