I am trying a comms library in which you put data into an uint8_t array, execute a send command, and it comes out the other end in an unint8_t array.
I need to transmit integers greater than 256.
To test my casting I wrote the following sketch:
uint8_t InBuffer[] = {"300"};
int x = 999;
void setup()
{
delay(2000);
Serial.begin(19200);
itoa(x, (char*)InBuffer, 10);
Serial.println((char*)InBuffer);
Serial.println(2 * atoi((char*)InBuffer));
int y = atoi((char*)InBuffer);
Serial.println(y);
}
void loop()
{
//Serial.println("Looping..");
delay(1000);
}
While this code seems to work OK I question the seemingly verbose and inefficient " int y = atoi((char*)InBuffer);" and " itoa(x, (char*)InBuffer, 10);" each with their double conversions.
Is there a more eloquent and efficient way to put and extract a large integer from an uint8_t array?