电路图
将arduino的引脚11连接到橙色led的正极引线,通过220欧姆电阻将led的负极引线连接到arduino的地。类似地,通过220欧姆电阻将白色led的正极引线连接到arduino的引脚10和led的负极引线连接到arduino。
程序入门
首先,在arduino ide中加载下面为arduino提供的代码。然后上传给定代码以在ide中处理。
之后,打开wekinator并将输入更改为1并输出为2并离开另一个选项。
点击“下一步”,会出现一个新窗口。现在从处理的输入窗口,单击橙色框,在wekinator中,在输出-1框中输入1,然后开始录制半秒。
现在,单击处理中的白色框,在wekinator中,在输出-1框中输入0并在输出-2框中输入1并开始记录半秒。
现在点击“train”,然后点击“run”。现在,当您点击橙色框时,连接到引脚11的led将亮起,当您单击白色框时,连接到arduino引脚10的led将亮起。
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;
// initializing the pins for led‘s
int orange_led = 11;
int white_led = 10;
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);
pinmode(white_led, output);
pinmode(orange_led, output);
// synchronizing the variables with the processing. the variables must be int type.
receiver.observe(output);
receiver.observe(output1);
}
void loop()
{
// receiving the output from the processing.
receiver.sync();
// matching the received output to light up led’s
if (output == 1)
{
digitalwrite(orange_led, high);
}
else if (output == 0)
{
digitalwrite(orange_led, low);
}
if (output1 == 1)
{
digitalwrite(white_led, high);
}
else if(output1 == 0)
{
digitalwrite(white_led, low);
}
}
处理代码(输入到wekinator)
// importing the library which will help us in communicating with the wekinator
import oscp5.*;
import netp5.*;
//creating the instances
oscp5 oscp5;
netaddress dest;
float bx;
void setup() {
// size of output window
size(400, 100, p3d);
// starting the communication with wekinator. listen on port 9000, return messages on port 6448
oscp5 = new oscp5(this,9000);
dest = new netaddress(“127.0.0.1”,6448);
}
void draw() {
// creating the boxes in window
blocks();
// send the osc message to wekinator
sendosc();
}
void mousepressed()
{
if (mousex 》 25 && mousex 《 75)
{
bx=1;
}
if (mousex 》 325 && mousex 《 375)
{
bx=2;
}
}
void sendosc() {
oscmessage msg = new oscmessage(“/wek/inputs”);
msg.add((float)bx);
oscp5.send(msg, dest);
}
void blocks()
{
background(0);
fill(255, 155, 0);
rect(25, 25, 50, 50);
fill(255, 255, 255);
rect(325, 25, 50, 50);
}
处理代码(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 value1 = theoscmessage.get(1).floatvalue(); // second output
// converting the output to int type
output = int(value);
output1 = int(value1);
}
}
void draw()
{
// nothing to be drawn for this example
}
5G高频特性将使GaN技术使用领域延伸
晶瑞股份拟在湖北省潜江市投资建设微电子材料项目 项目总投资15.2亿元
亚马逊云科技直挂云帆济沧海,助力中国企业致胜海外
人工智能可以像人一样描述图像?
2030年太阳能将成为能源系统的支柱
如何训练Wekinator控制Arduino
全球聚集千万炒币大军 高效安全的H网应运而生
ST和Microchip等品牌MCU微控制器的分类及特点
浪潮在5G小基站的探索与实践探讨
康奈尔大学创造可感觉形状纹理的软性机器人手
2019年上半年中国智能手机出货量同比下滑5.4%,5G和终端流速成未来关注重点
物联网和AI发展迅速,嵌入式的发展前景如何
网络攻击我们可以预防吗
全球智能手机利润分布:苹果继续老大,华米OV占20%
拍字节新型3D铁电存储器(VFRAM)-P95S128KSWSP3TF在新型语音电子门锁系统中的应用
LED光源产品符合DLC5.0版本标准要求
什么是工控机_工控机能当电脑用吗
高压直流电源和高压交流电源俩者区别?
物联网是什么问题的答案
iphone8什么时候上市最新消息:iphone8真机图赏,双后置摄像头+无线充电+指纹识别,9月17日不见不散