I have the following code:
uint8_t buf[1];
uint8_t buflen = 1;
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);//this prints out okay
highPins[(char*)buf] = 1;
}
The problem is in highPins[(char*)buf]. highPins is array, and in (char*)buf I get index number. When I display it with Serial.println, it shows the number, but here it does not. I am guessing its because (char*)buf is not a number. I have tried to convert it to int with few functions I have found online, but it was unsuccessful. Any help is appreciated :)
String(buf).toInt()
is how i do it, but there might be better ways...highPins[buf[0] - '0'] = 1;
should do the trick :)Serial.println(const char[])
expects a NUL-terminated buffer. It will read your memory starting at&buf
and continue until it finds a NUL byte.