hongshimizi 发表于 2015-9-28 13:10:36

可以用蓝牙给arduino发送初始值吗?

我还没有入手蓝牙模块,但是感觉是和串口通信一样的东西吧。我看到的都是在setup里面定义seria。XX(9600)的,然后在loop里面val=serial,read()的。这是每次循环我都得输一次的意思啊。。。。。。我想可以不可以发送一个端口定义的数组,在setup里,然后loop就按照我的端口定义工作。我复位在发一个新的端口定义数组。然后loop又按新的端口定义工作?我不是学软件的,代码不擅长,还请熟悉代码的高手不吝赐教。我诚心感谢。

avanyway 发表于 2015-9-30 13:42:14

/*
Mega multple serial test

Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).

This example works only on the Arduino Mega

The circuit:
* Any serial device attached to Serial port 1
* Serial monitor open on Serial port 0:

created 30 Dec. 2008
modified 20 May 2012
by Tom Igoe & Jed Roach

This example code is in the public domain.

*/


void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial3.begin(9600);
Serial.println("Hello!");
Serial.println("XBEE TEST RX!");
}


void loop() {
      char Byte;
      if(Serial.available()){
      Byte=Serial.read();
      Serial.print(Byte);
}
}------------------------------------------可以参考一下啊

hongshimizi 发表于 2015-9-30 20:01:56

avanyway 发表于 2015-9-30 13:42 static/image/common/back.gif
/*
Mega multple serial test



谢谢,你这个很管用,我也会了一些简单的了,因为我主要用到digtalWrite功能,所以可以在setup里把需要的端口都一定义,然后串口一次发送一个数嘛,依次赋值给变量,然后digtalWrite里面写上对应的变量。我现在已经可以用了:loveliness:
页: [1]
查看完整版本: 可以用蓝牙给arduino发送初始值吗?