从蓝牙接收的项目不是打印的项目
received items from bluetooth not as printed ones
我正在开发一个项目,通过蓝牙将一些数字发送到arduino超级板,因此当我直接打印发送的项目时,它们显示正确。但是当我将这些数字存储在一个数组中并尝试打印它们时,它们显示为不同的数字。这些数字是从我的智能手机中以整数形式发送的。这是我的代码:
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(51, 11); // RX, TX
int BluetoothData; // the data given from Computer
boolean oneTime = true; //ensures data is received only once
int myInts[1000];
int counter = 0; // count the number of sent items
void setup() {
Genotronex.begin(9600);
Serial.begin(9600);
Serial.println("Bluetooth On");
pinMode(ledpin,OUTPUT);
}
void loop() {
if (Genotronex.available() && oneTime == true){
BluetoothData=Genotronex.read();
Serial.println(BluetoothData); // <== This shows the right numbers
myInts[counter] = BluetoothData; //add the integers in an array
counter++;
if (BluetoothData==231){ // to know that the array is fully sent once
oneTime = false;
Serial.println("Done");
counter--; //i dont want to print the last element
for(int a=0; a < counter; a=a+2){
Serial.print("Bearing: ");
Serial.print((myInts[a])); // <== This shows wrong numbers
Serial.print(" ");
Serial.print("Distance: ");
Serial.println((myInts[a]+2));
}
}
}
delay(100);// prepare for next data ...
}
有人能帮帮我吗。非常感谢。
我犯了一个愚蠢的错误
Serial.println((myInts[a]+2));
应该是
Serial.println((myInts[a+1]));
我认为
Serial.print((myInts[a]));
应该是
Serial.println((myInts[a]));
能够将int打印为ASCII。
相关文章:
- 如何循环打印顶点结构
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法在 CLion 中构建 C++ 项目
- 运行同一解决方案的另一个项目的项目
- 在 Eclipse 中漂亮的打印C++适用于某些项目,而不适用于其他项目
- 一个循环,可以打印所有项目(无论链条多长时间) *指针
- 用字母打印以 10-16 为基数(我被困在一个必须打印出任何数字的项目上)
- 为项目和循环创建简单的控制菜单会比预期打印提示的次数更多
- 如何在复杂的CPP项目中在gdb中打印犰狳矩阵
- Arduino 项目需要打印语句才能工作
- 将QQuick项目打印到打印机
- 如何处理混合模式项目中的打印
- 打印出链接列表中的项目
- 打印出枚举标志中的选定项目
- 为什么我的 c++ 程序没有打印链接列表的所有项目?
- 打印C++项目中的所有代码列表
- 从蓝牙接收的项目不是打印的项目
- C++:新建空项目(如何创建,添加main方法并打印"Hello, world")?
- f流<无法读取内存>。打印列表中所有项目时遇到问题