从蓝牙接收的项目不是打印的项目

received items from bluetooth not as printed ones

本文关键字:项目 打印      更新时间:2023-10-16

我正在开发一个项目,通过蓝牙将一些数字发送到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。