极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10534|回复: 2

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

[复制链接]
发表于 2015-9-28 13:10:36 | 显示全部楼层 |阅读模式
我还没有入手蓝牙模块,但是感觉是和串口通信一样的东西吧。我看到的都是在setup里面定义seria。XX(9600)的,然后在loop里面val=serial,read()的。这是每次循环我都得输一次的意思啊。。。。。。我想可以不可以发送一个端口定义的数组,在setup里,然后loop就按照我的端口定义工作。我复位在发一个新的端口定义数组。然后loop又按新的端口定义工作?我不是学软件的,代码不擅长,还请熟悉代码的高手不吝赐教。我诚心感谢。
回复

使用道具 举报

发表于 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);  
  }
}------------------------------------------可以参考一下啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-9-30 20:01:56 | 显示全部楼层
avanyway 发表于 2015-9-30 13:42
/*
  Mega multple serial test

谢谢,你这个很管用,我也会了一些简单的了,因为我主要用到digtalWrite功能,所以可以在setup里把需要的端口都一定义,然后串口一次发送一个数嘛,依次赋值给变量,然后digtalWrite里面写上对应的变量。我现在已经可以用了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 15:57 , Processed in 0.069917 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表