0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何訓(xùn)練Wekinator控制Arduino

454398 ? 來源:工程師吳畏 ? 2019-07-31 09:00 ? 次閱讀

電路圖

Arduino的引腳11連接到橙色LED的正極引線,通過220歐姆電阻將LED的負極引線連接到Arduino的地。類似地,通過220歐姆電阻將白色LED的正極引線連接到Arduino的引腳10和LED的負極引線連接到Arduino。

如何訓(xùn)練Wekinator控制Arduino

程序入門

首先,在Arduino IDE中加載下面為Arduino提供的代碼。然后上傳給定代碼以在IDE中處理。

之后,打開Wekinator并將輸入更改為1并輸出為2并離開另一個選項。

點擊“下一步”,會出現(xiàn)一個新窗口?,F(xiàn)在從處理的輸入窗口,單擊橙色框,在Wekinator中,在輸出-1框中輸入1,然后開始錄制半秒。

現(xiàn)在,單擊處理中的白色框,在Wekinator中,在輸出-1框中輸入0并在輸出-2框中輸入1并開始記錄半秒。

現(xiàn)在點擊“Train”,然后點擊“Run”。現(xiàn)在,當您點擊橙色框時,連接到引腳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

}

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • Arduino
    +關(guān)注

    關(guān)注

    187

    文章

    6455

    瀏覽量

    186357
收藏 人收藏

    評論

    相關(guān)推薦

    電磁干擾訓(xùn)練系統(tǒng)原理是什么

    智慧華盛恒輝電磁干擾訓(xùn)練系統(tǒng)的原理主要基于電磁干擾(EMI)的基本原理,即利用電磁波對電子設(shè)備或系統(tǒng)產(chǎn)生的干擾,通過模擬真實的電磁環(huán)境,對受訓(xùn)人員進行電磁干擾應(yīng)對能力的訓(xùn)練。以下是電磁干擾訓(xùn)練系統(tǒng)
    的頭像 發(fā)表于 07-22 16:34 ?255次閱讀

    海上電磁干擾訓(xùn)練系統(tǒng)

    智慧華盛恒輝海上電磁干擾訓(xùn)練系統(tǒng)是一種專門用于模擬海上電磁環(huán)境、訓(xùn)練人員應(yīng)對電磁干擾能力的系統(tǒng)。以下是對海上電磁干擾訓(xùn)練系統(tǒng)的詳細解析: 智慧華盛恒輝系統(tǒng)概述 智慧華盛恒輝海上電磁干擾訓(xùn)練
    的頭像 發(fā)表于 07-15 16:05 ?197次閱讀

    【大語言模型:原理與工程實踐】大語言模型的預(yù)訓(xùn)練

    大語言模型的核心特點在于其龐大的參數(shù)量,這賦予了模型強大的學(xué)習(xí)容量,使其無需依賴微調(diào)即可適應(yīng)各種下游任務(wù),而更傾向于培養(yǎng)通用的處理能力。然而,隨著學(xué)習(xí)容量的增加,對預(yù)訓(xùn)練數(shù)據(jù)的需求也相應(yīng)
    發(fā)表于 05-07 17:10

    arduino控制步進電機代碼

    Arduino是一種開放源代碼的電路板平臺,它可以用于控制各種不同的電子設(shè)備,包括步進電機。步進電機是一種電動機,可以通過下達特定的指令來控制每個步進的角度,從而使電機旋轉(zhuǎn)到指定的位置。在本文
    的頭像 發(fā)表于 02-14 16:29 ?1760次閱讀

    arduino中while循環(huán)怎么跳出

    執(zhí)行某段代碼的情況。然而,如何在合適的時機跳出 while 循環(huán)是一個需要注意的問題。本文將詳細介紹 Arduino 中 while 循環(huán)的基本概念,以及如何使用不同的技巧跳出該循環(huán)來實現(xiàn)代碼的靈活控制
    的頭像 發(fā)表于 02-14 16:22 ?2140次閱讀

    如何使用Arduino控制RGB LED

    在本指南中,您將學(xué)習(xí)如何使用Arduino控制RGB LED。RGB(紅-綠-藍)LED可以通過混合不同強度的紅、綠、藍光來產(chǎn)生多種顏色。您將學(xué)習(xí)創(chuàng)建一個基本Arduino RGB LED電路,并以一些基本顏色為例循環(huán)。
    的頭像 發(fā)表于 02-11 10:28 ?4126次閱讀
    如何使用<b class='flag-5'>Arduino</b><b class='flag-5'>控制</b>RGB LED

    如何使用Arduino UNO板和電位器控制伺服電機

    在本Arduino伺服電機教程中,您將學(xué)習(xí)如何使用Arduino UNO板和電位器控制伺服電機。
    的頭像 發(fā)表于 02-11 10:11 ?2235次閱讀
    如何使用<b class='flag-5'>Arduino</b> UNO板和電位器<b class='flag-5'>控制</b>伺服電機

    如何使用Arduino UNO和TIP120晶體管驅(qū)動和控制直流電機的速度

    在本 Arduino 電機指南中,您將學(xué)習(xí)如何使用 Arduino UNO 和 TIP120晶體管驅(qū)動和控制直流電機的速度。在此示例中,您將使用按鈕來提高電機速度,然后減慢速度,這要歸功于脈寬調(diào)制 (PWM) 的強大功能。
    的頭像 發(fā)表于 02-11 10:08 ?1078次閱讀
    如何使用<b class='flag-5'>Arduino</b> UNO和TIP120晶體管驅(qū)動和<b class='flag-5'>控制</b>直流電機的速度

    如何設(shè)置Arduino IR發(fā)射器電路

    在本指南中,您將學(xué)習(xí)如何設(shè)置 Arduino IR發(fā)射器電路。它使您可以控制IR(紅外線)LED,并從Arduino發(fā)送任何遠程控制代碼。這意味著你可以用它來
    的頭像 發(fā)表于 02-11 09:44 ?760次閱讀
    如何設(shè)置<b class='flag-5'>Arduino</b> IR發(fā)射器電路

    如何使用arduino控制接觸器?

    我將避免鉛酸電池過載。我想通過使用近 30A 的接觸器和 arduino uno 板來控制電池過載。如何使用arduino控制接觸器?
    發(fā)表于 01-22 07:14

    arduino和單片機的區(qū)別比較

    和軟件的微控制器平臺,它通過一種簡化和標準化的方式,使電子開發(fā)變得更加容易。Arduino主板上集成了處理器、輸入輸出引腳、電源供應(yīng)等電路,能夠連接各種傳感器和執(zhí)行器,通過編程進行控制和交互。
    的頭像 發(fā)表于 01-02 16:18 ?9058次閱讀

    工程師說 | 使用Chat-GPT為RL78 MCU(Arduino)編寫AI代碼

    使用時需要注意這一點。 什么是Arduino? Arduino是一個用于輕松進行電子項目的開源平臺。它由一個配備有微控制器的板(Arduino板)和一個軟件開發(fā)
    的頭像 發(fā)表于 12-21 18:20 ?921次閱讀
    工程師說 | 使用Chat-GPT為RL78 MCU(<b class='flag-5'>Arduino</b>)編寫AI代碼

    基于WiFi的Arduino網(wǎng)絡(luò)控制方案

    電子發(fā)燒友網(wǎng)站提供《基于WiFi的Arduino網(wǎng)絡(luò)控制方案.rar》資料免費下載
    發(fā)表于 11-10 10:30 ?0次下載
    基于WiFi的<b class='flag-5'>Arduino</b>網(wǎng)絡(luò)<b class='flag-5'>控制</b>方案

    能否用arduino代替PLC做機器的控制

    能否用arduino代替PLC做機器的控制?
    發(fā)表于 11-09 08:06

    Arduino提供的PWM控制功能入門(1)

    今天來學(xué)習(xí)一下 Arduino 提供的 PWM 控制功能,它可以用來控制電機轉(zhuǎn)速,LED 明亮等。
    的頭像 發(fā)表于 10-31 16:32 ?2200次閱讀
    <b class='flag-5'>Arduino</b>提供的PWM<b class='flag-5'>控制</b>功能入門(1)