i made a silly mistake
Serial.println((myInts[a]+2));
should be
Serial.println((myInts[a+1]));
Question
i am developing a project that i send some numbers via bluetooth to the arduino mega board, so when i print the sent items directly they show correct. but when i store these numbers in an array and try to print them they show as different numbers. The numbers are sent as integers from my smartphone. here is my code:
#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 ...
}
can someone please help me. Thank you.
Solution
i made a silly mistake
Serial.println((myInts[a]+2));
should be
Serial.println((myInts[a+1]));
OTHER TIPS
I think
Serial.print((myInts[a]));
should be
Serial.println((myInts[a]));
to be able to print ints as ASCII.