我正试图通过蓝牙从我的智能手机发送一些号码给我的Arduino。我把所有的东西都连接好了,而且工作得很好,但我的问题是发送负数。
例如,我尝试发送-173 (bin:11111111 01010011),它只接收83 (bin:00000000 01010011),这是第二个字节。我试图使用长的或双的或有符号的int来代替整数,但是我失败了。
下面是我使用的代码:
#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 ...
}发布于 2014-05-05 08:50:23
尝试使用Serial.write而不是Serial.print。我有一个类似的设备,它在Serial.write上运行得很好
https://stackoverflow.com/questions/23448131
复制相似问题