am trying to create an array of char but i think i have failed to using indexing properly to read characters in some sequence.
char incomingbyte[37]; // for incoming serial data
int val =0;
int i;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
i=0;
while(i<37){
if (Serial.available()>0){
val=Serial.read();
if (i==37){
break;
}
incomingbyte*=val;*
am trying to create an array of char but i think i have failed to using indexing properly to read characters in some sequence.
You have not failed to use indexing properly, you have failed to use indexing at all.incomingbyte=val;The code you posted does not compile but the error that it gives is a clue as to what is wrong. Once you have sorted out the problem with indexing the array you can tackle the other problems like what happens if more or less than 37 bytes are received, the fact that the array needs to be terminated before it can be treated as a string and printed and its size if a terminator is to be added.
Naming an array of chars incomingbyte could cause confusion at some point too. If you were to put your code in code tags when posting it here then it would be easier to read.