Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在2 mBots(Arduino)之间通过红外(IR)发送和接收数据_Arduino_Infrared - Fatal编程技术网

在2 mBots(Arduino)之间通过红外(IR)发送和接收数据

在2 mBots(Arduino)之间通过红外(IR)发送和接收数据,arduino,infrared,Arduino,Infrared,我有两个MBOT(Arduino机器人),我想知道如何与板上的红外传感器进行通信。我所达到的最大值是在mBot中检测遥控器上的按钮脉冲。我真正想做的是将INT从第一个mBot发送到第二个mBot,但看起来mBot红外代码只用于检测遥控按钮脉冲。如果我可以从第一个mBot发送当你按下按钮到第二个mBot时发送遥控器的相同脉冲,那么我可以做一个切换案例,将接收到的按钮脉冲(例如按钮0)转换成一个数字(int received=0) 与其这样做,不如直接发送和接收int,甚至字符串。但在这一点上,任何

我有两个MBOT(Arduino机器人),我想知道如何与板上的红外传感器进行通信。我所达到的最大值是在mBot中检测遥控器上的按钮脉冲。我真正想做的是将INT从第一个mBot发送到第二个mBot,但看起来mBot红外代码只用于检测遥控按钮脉冲。如果我可以从第一个mBot发送当你按下按钮到第二个mBot时发送遥控器的相同脉冲,那么我可以做一个切换案例,将接收到的按钮脉冲(例如按钮0)转换成一个数字(int received=0)

与其这样做,不如直接发送和接收int,甚至字符串。但在这一点上,任何用红外线与两个MBOT通信的方法对我来说都是好的

这是我用来检测mBot中遥控器按钮脉冲的代码:

include Wire.h 
include SoftwareSerial.h 
include MeMCore.h

MeIR ir;
MeBuzzer buzzer;

void setup()
{

ir.begin();

}

void loop(){

if(ir.keyPressed(22)) // receive button 0 pulse
buzzer.tone(460,200); // make a beep 
}
有人知道如何在两个MBOT之间发送和接收数据的代码吗?(即使只是按钮编号从0到9的脉冲)

请记住,因为这些机器人并不完全是arduino uno板,正常的arduino使用红外传感器的方式将无法工作,因为mBot有自己的构建和库

任何帮助都将被感谢

解决

如何通过红外与两个MBOT通信:

1:下载Arduino iRemote库:

2:转到C/programs/Arduino/libraries并删除默认的IR库,因为它与此库不同,并且会导致不兼容。然后复制Arduino IRemote库文件夹,将其添加到Arduino库中

3:打开makeblock库,在文件MeMCore.h中注释第68行(//#include“MeIR.h”)。这也是为了避免不兼容

最后,您可以将草图上传到mBot,通过infrarred发送和接收数据。以下是发送和接收数据的代码:

通过红外发送数据:

#include <IRremote.h>

IRsend irsend;

int robot_ori=91;
int n_coordenadas=4;
int x[10], y[10];

void setup()
{
  x[1]=200;   y[1]=217;
  x[2]=199;   y[2]=213;
  x[3]=210;   y[3]=179;
  x[4]=212;   y[4]=140;
}

void loop() 
{

  irsend.sendSony(robot_ori, 16);   // data to send, nº of bits to send 
  delay(40);                        // for int type is 16 bits
  irsend.sendSony(n_coordenadas, 16); 
  delay(40);

  for (int i = 1; i <= n_coordenadas; i++) 
  {
    irsend.sendSony(x[i], 16);
    delay(40);  
    irsend.sendSony(y[i], 16);        
    delay(40);
  }

  delay(5000); //5 second delay between each signal burst

}
#include <IRremote.h>

int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC); // DEC decimal, HEX hexadecimal, etc
    irrecv.resume(); // Receive the next value
  }
}
#包括
欧文·欧文;
int robot_ori=91;
int n_coordenadas=4;
int x[10],y[10];
无效设置()
{
x[1]=200;y[1]=217;
x[2]=199;y[2]=213;
x[3]=210;y[3]=179;
x[4]=212;y[4]=140;
}
void循环()
{
sendSony(robot_ori,16);//要发送的数据,nº位要发送
延迟(40);//int类型为16位
森索尼(n_coordenadas,16);
延迟(40);
对于(int i=1;i已解决

如何通过红外与两个MBOT通信:

1:下载Arduino iRemote库:

2:转到C/programs/Arduino/libraries并删除默认的IR库,因为它与此库不同,并且会导致不兼容。然后复制Arduino Iremote库文件夹以将其添加到Arduino库中

3:打开makeblock库,在文件MeMCore.h中注释第68行(//#include“MeIR.h”)。这也是为了避免不兼容

最后,您可以将草图上传到mBot,通过infrarred发送和接收数据。以下是发送和接收数据的代码:

通过红外发送数据:

#include <IRremote.h>

IRsend irsend;

int robot_ori=91;
int n_coordenadas=4;
int x[10], y[10];

void setup()
{
  x[1]=200;   y[1]=217;
  x[2]=199;   y[2]=213;
  x[3]=210;   y[3]=179;
  x[4]=212;   y[4]=140;
}

void loop() 
{

  irsend.sendSony(robot_ori, 16);   // data to send, nº of bits to send 
  delay(40);                        // for int type is 16 bits
  irsend.sendSony(n_coordenadas, 16); 
  delay(40);

  for (int i = 1; i <= n_coordenadas; i++) 
  {
    irsend.sendSony(x[i], 16);
    delay(40);  
    irsend.sendSony(y[i], 16);        
    delay(40);
  }

  delay(5000); //5 second delay between each signal burst

}
#include <IRremote.h>

int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC); // DEC decimal, HEX hexadecimal, etc
    irrecv.resume(); // Receive the next value
  }
}
#包括
欧文·欧文;
int robot_ori=91;
int n_coordenadas=4;
int x[10],y[10];
无效设置()
{
x[1]=200;y[1]=217;
x[2]=199;y[2]=213;
x[3]=210;y[3]=179;
x[4]=212;y[4]=140;
}
void循环()
{
sendSony(robot_ori,16);//要发送的数据,nº位要发送
延迟(40);//int类型为16位
森索尼(n_coordenadas,16);
延迟(40);
对于(int i=1;i