电路图
将其中一个蜂鸣器的正极连接到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文章
6469浏览量
187094 -
手势控制
+关注
关注
4文章
44浏览量
21726
发布评论请先 登录
相关推荐
评论