電路圖
將其中一個蜂鳴器的正極連接到Arduino的9針和Arduino的10針的另一個蜂鳴器的正面。然后將兩個蜂鳴器的負片連接到項目的Arduino.section的地面。
如何運行代碼
首先,在Arduino IDE中粘貼為本文末尾的Arduino提供的代碼并上傳代碼。
然后您需要從Wekinator的示例頁面下載草圖。
下載源代碼以處理簡單的10x10顏色網格。解壓縮并在處理中運行代碼。該程序將使用您的筆記本電腦的網絡攝像頭,根據您在攝像頭前所做的操作,它將為Wekinator提供輸入。
您需要另一個草圖來輸出Wekinator的輸出。這篇文章末尾的草圖代碼。將其粘貼到處理中并運行草圖。這個草圖將從Wekinator輸出并將其發送到Arduino,蜂鳴器將播放不同的聲音。
兩個處理窗口應如下所示。
現在打開Wekinator并進行如下圖所示的設置。將輸入設置為100,將輸出設置為2.將類型設置為“自定義”,然后單擊“配置”。
點擊“配置”時“,一個新窗口將打開,如下所示。更改設置,如下圖所示。
現在退出網絡攝像頭并點擊“隨機化”。開始錄制半秒。
現在將右手顯示在網絡攝像頭的右側,然后單擊“隨機化”。然后開始錄制半秒。
現在將左手顯示在網絡攝像頭的左側,然后單擊“隨機化”。然后開始錄制半秒。
然后,單擊“訓練”,然后單擊“運行”。現在,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文章
6477瀏覽量
188069 -
手勢控制
+關注
關注
4文章
44瀏覽量
21863
發布評論請先 登錄
相關推薦
評論