0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

如何训练Wekinator控制Arduino

454398 来源:工程师吴畏 2019-07-31 09:00 次阅读

电路图

Arduino的引脚11连接到橙色LED的正极引线,通过220欧姆电阻将LED的负极引线连接到Arduino的地。类似地,通过220欧姆电阻将白色LED的正极引线连接到Arduino的引脚10和LED的负极引线连接到Arduino。

如何训练Wekinator控制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

}

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • Arduino
    +关注

    关注

    184

    文章

    6427

    浏览量

    184832
收藏 人收藏

    评论

    相关推荐

    如何使用Arduino控制RGB LED

    在本指南中,您将学习如何使用Arduino控制RGB LED。RGB(红-绿-蓝)LED可以通过混合不同强度的红、绿、蓝光来产生多种颜色。您将学习创建一个基本Arduino RGB LED电路,并以一些基本颜色为例循环。
    的头像 发表于 02-11 10:28 1390次阅读
    如何使用<b class='flag-5'>Arduino</b><b class='flag-5'>控制</b>RGB LED

    如何使用Arduino UNO板和电位器控制伺服电机

    在本Arduino伺服电机教程中,您将学习如何使用Arduino UNO板和电位器控制伺服电机。
    的头像 发表于 02-11 10:11 670次阅读
    如何使用<b class='flag-5'>Arduino</b> UNO板和电位器<b class='flag-5'>控制</b>伺服电机

    如何使用arduino控制接触器?

    我将避免铅酸电池过载。我想通过使用近 30A 的接触器和 arduino uno 板来控制电池过载。如何使用arduino控制接触器?
    发表于 01-22 07:14

    基于WiFi的Arduino网络控制方案

    电子发烧友网站提供《基于WiFi的Arduino网络控制方案.rar》资料免费下载
    发表于 11-10 10:30 0次下载
    基于WiFi的<b class='flag-5'>Arduino</b>网络<b class='flag-5'>控制</b>方案

    如何使用Python和PinPong库控制Arduino

    与传感器和其他物理设备集成的应用程序。如果您已经掌握了Python的基础知识,那么您可以通过使用Python来控制Arduino来入门。本文目的主要是向您展示如何使用PinPong库通过Python
    的头像 发表于 10-13 10:59 446次阅读
    如何使用Python和PinPong库<b class='flag-5'>控制</b><b class='flag-5'>Arduino</b>

    基于arduino设计的手势控制小车

    基于arduino的手势控制小车
    发表于 09-25 06:06

    Arduino的PWM控制代码

    如果你需要一个具体的代码示例,我可以为你提供一个Arduino的PWM控制代码。Arduino是一款常用的开源电子原型平台,它提供了PWM功能。以下是一个简单的Arduino代码示例,
    发表于 09-21 08:57

    Arduino和Android窗帘控制

    电子发烧友网站提供《Arduino和Android窗帘控制.zip》资料免费下载
    发表于 07-12 10:01 1次下载
    <b class='flag-5'>Arduino</b>和Android窗帘<b class='flag-5'>控制</b>

    Arduino球和光束控制系统

    电子发烧友网站提供《Arduino球和光束控制系统.zip》资料免费下载
    发表于 07-10 11:28 0次下载
    <b class='flag-5'>Arduino</b>球和光束<b class='flag-5'>控制</b>系统

    制作Arduino控制的机器人

    电子发烧友网站提供《制作Arduino控制的机器人.zip》资料免费下载
    发表于 07-06 14:21 0次下载
    制作<b class='flag-5'>Arduino</b><b class='flag-5'>控制</b>的机器人

    使用Arduino的Android控制RGB LED灯条

    电子发烧友网站提供《使用Arduino的Android控制RGB LED灯条.zip》资料免费下载
    发表于 07-05 09:45 2次下载
    使用<b class='flag-5'>Arduino</b>的Android<b class='flag-5'>控制</b>RGB LED灯条

    DIY安卓+Arduino控制迷宫游戏

    电子发烧友网站提供《DIY安卓+Arduino控制迷宫游戏.zip》资料免费下载
    发表于 06-29 14:53 0次下载
    DIY安卓+<b class='flag-5'>Arduino</b><b class='flag-5'>控制</b>迷宫游戏

    蓝牙控制Arduino机器人

    电子发烧友网站提供《蓝牙控制Arduino机器人.zip》资料免费下载
    发表于 06-27 10:24 0次下载
    蓝牙<b class='flag-5'>控制</b>的<b class='flag-5'>Arduino</b>机器人

    如何制作Arduino蓝牙控制的汽车

    电子发烧友网站提供《如何制作Arduino蓝牙控制的汽车.zip》资料免费下载
    发表于 06-26 10:21 0次下载
    如何制作<b class='flag-5'>Arduino</b>蓝牙<b class='flag-5'>控制</b>的汽车

    Arduino Arduboy控制台开源分享

    电子发烧友网站提供《Arduino Arduboy控制台开源分享.zip》资料免费下载
    发表于 06-15 09:51 0次下载
    <b class='flag-5'>Arduino</b> Arduboy<b class='flag-5'>控制</b>台开源分享