Hi, Im working on a project in which I need to communicate an int from Arduino Tx to Arduino Rx. Im using the Software Serial library and I've created an aux Channel called CanalAux.
I found a code, which works, but I don't understand it. Could someone help me? Thanks!
unsigned int readFromTx() {
unsigned int val;
val = Serial.read();
val += ((unsigned int)Serial.read())*256;
return val;
}
I understand the read function reads a byte, thats why I have to cast it to an int. But why multiply by 256?
//Sends and int by CanalAux
#define VAL_SIZE 2
void writeCanalAux(int val)
{
CanalAux.write((byte*)&val, VAL_SIZE);
}
I understand the write receives a byte, thats why i cast the val to a byte. What does the * and the & do??
Thanks a lot!!!