首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >arduino通过蓝牙接收错误的号码

问arduino通过蓝牙接收错误的号码
EN

Stack Overflow用户
提问于 2014-05-03 18:10:41
回答 1查看 1K关注 0票数 0

我正试图通过蓝牙从我的智能手机发送一些号码给我的Arduino。我把所有的东西都连接好了,而且工作得很好,但我的问题是发送负数。

例如,我尝试发送-173 (bin:11111111 01010011),它只接收83 (bin:00000000 01010011),这是第二个字节。我试图使用长的或双的或有符号的int来代替整数,但是我失败了。

下面是我使用的代码:

代码语言:javascript
复制
#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Genotronex(51, 11); // RX, TX
int ledpin=53; // led on D13 will show blink on / off
BluetoothData; // the data given from Computer

void setup() {
  // put your setup code here, to run once:
  Genotronex.begin(9600);
  Serial.begin(9600);
  Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
  pinMode(ledpin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
   if (Genotronex.available()){
    BluetoothData=Genotronex.read();
    Serial.print(BluetoothData);
   }

}
delay(100);// prepare for next data ...
}
EN

回答 1

Stack Overflow用户

发布于 2014-05-05 08:50:23

尝试使用Serial.write而不是Serial.print。我有一个类似的设备,它在Serial.write上运行得很好

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23448131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档