Reputation: 3
I am trying to interpret a signal that is sent to my by lazer as a string but I keep getting: 00000000!� instead of 00000000
Here is the code I used to interpret it
String recievePacket(){
char signals [8];
for(int i = 0; i < 8; i ++){
lightRead = analogRead(lightPin);
if(lightRead < 50){
signals[i] = '1';
}
else{
signals[i] = '0';
}
delay(50);
}
String signalStr(signals);
return signalStr;
}
Upvotes: 0
Views: 35
Reputation: 8237
Strings in C are null terminated. Try
char signals[9];
for ...
}
signals[8] = 0;
delay...
Upvotes: 1