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
    +关注

    关注

    188

    文章

    6478

    浏览量

    188396
收藏 人收藏

    评论

    相关推荐

    华为公布AI模型训练与车辆控制专利

    近日,华为技术有限公司在技术创新领域再次迈出重要一步,其申请的“模型的训练方法、车辆的控制方法及相关装置”专利于2月18日正式公布。这一专利的公布标志着华为在人工智能领域的又一重大突破。 据专利摘要
    的头像 发表于 02-20 09:14 193次阅读

    如何使用Arduino实现CAN总线通信呢

    CAN(Controller Area Network)总线是一种常用于汽车和工业控制系统的串行通信协议,以其高可靠性和实时性而闻名。Arduino,作为一种流行的开源微控制器平台,可以通过附加
    的头像 发表于 12-23 09:06 725次阅读

    HAL库在Arduino平台上的使用

    HAL库在Arduino平台上的使用 Arduino平台是一个开源的电子原型平台,它包括硬件(基于微控制器的电路板)和软件(Arduino IDE)。
    的头像 发表于 12-02 14:04 615次阅读

    基于Arduino的串口通信项目

    基于Arduino的串口通信项目涉及多个方面,包括硬件连接、软件编程、串口参数配置等。 一、硬件准备 Arduino开发板 :确保你有一块Arduino开发板,如Arduino Uno
    的头像 发表于 11-22 09:24 975次阅读

    stm32与Arduino的比较

    在微控制器的世界里,STM32和Arduino是两个经常被提及的名字。STM32是一系列由STMicroelectronics生产的高性能微控制器,而Arduino则是一个开源电子原型
    的头像 发表于 11-19 15:45 2192次阅读

    如何使用Arduino实现CAN总线通信

    CAN总线(Controller Area Network)是一种多主控制的串行通信协议,广泛应用于汽车电子、工业自动化等领域。它以其高可靠性、实时性和灵活性而受到青睐。Arduino作为一个
    的头像 发表于 11-12 10:09 1604次阅读

    激光打靶射击训练系统 DW-S602提供军事训练效率

    激光打靶射击训练系统DW-S602是一套集激光技术、计算机技术、图像处理技术和传感器技术于一体的综合性射击训练系统。该系统通过模拟真实战场环境,为训练者提供逼真的射击体验,同时结合精确的数据
    的头像 发表于 11-03 09:54 517次阅读

    什么是协议分析仪和训练

    协议分析仪和训练器是两种不同但相关的设备或工具,它们在网络通信、电子设计和测试等领域发挥着重要作用。以下是对这两种设备的详细解释:一、协议分析仪 定义:协议分析仪(Protocol Analyzer
    发表于 10-29 14:33

    Arduino自制点焊机

    组装18650电池组,要用到点焊机,本文介绍用Arduino控制点焊机的点焊时间。
    发表于 07-29 10:14 6次下载

    电磁干扰训练系统原理是什么

    智慧华盛恒辉电磁干扰训练系统的原理主要基于电磁干扰(EMI)的基本原理,即利用电磁波对电子设备或系统产生的干扰,通过模拟真实的电磁环境,对受训人员进行电磁干扰应对能力的训练。以下是电磁干扰训练系统
    的头像 发表于 07-22 16:34 484次阅读

    海上电磁干扰训练系统

    智慧华盛恒辉海上电磁干扰训练系统是一种专门用于模拟海上电磁环境、训练人员应对电磁干扰能力的系统。以下是对海上电磁干扰训练系统的详细解析: 智慧华盛恒辉系统概述 智慧华盛恒辉海上电磁干扰训练
    的头像 发表于 07-15 16:05 333次阅读

    人脸识别模型训练流程

    人脸识别模型训练流程是计算机视觉领域中的一项重要技术。本文将详细介绍人脸识别模型的训练流程,包括数据准备、模型选择、模型训练、模型评估和应用部署等环节。 数据准备 数据是训练人脸识别模
    的头像 发表于 07-04 09:19 1246次阅读

    利用Arduino的自动风扇速度控制电路设计

    自动风扇速度控制电路Arduino LM35编程非常容易实验,可用于根据温度水平通过继电器控制任何目标设备。对于这里的温度测量,我们使用 LM35,这是一种精密集成电路温度器件,其输出电压与摄氏度
    的头像 发表于 06-22 16:39 2163次阅读
    利用<b class='flag-5'>Arduino</b>的自动风扇速度<b class='flag-5'>控制</b>电路设计

    【大语言模型:原理与工程实践】大语言模型的预训练

    大语言模型的核心特点在于其庞大的参数量,这赋予了模型强大的学习容量,使其无需依赖微调即可适应各种下游任务,而更倾向于培养通用的处理能力。然而,随着学习容量的增加,对预训练数据的需求也相应
    发表于 05-07 17:10

    谷歌模型训练软件有哪些?谷歌模型训练软件哪个好?

    谷歌在模型训练方面提供了一些强大的软件工具和平台。以下是几个常用的谷歌模型训练软件及其特点。
    的头像 发表于 03-01 16:24 1087次阅读