Hello! I am trying to send to values read from potentiometers on a master arduino, to a slave arduino. However I havn't been able to figure out how to format the values for the write function and them how to read them on the slave. Any help would be appreciated. Below is one of my attempts so far.
#define pot1 A0
#define pot2 A1
int value1 = 1;
int value2 = 1;
int x = analogRead(pot1);
value1 = map(x,0,1023,-255,255);
int y = analogRead(pot2);
value2 = map(y,0,1023,-255,255);
Wire.write((value1 >> 8));
Wire.write((value2 >> 8));
Where else would you specify the I2C address of the slave?
Part of the OPs problem is declaring local variables for value1 and value2 in receiveEvent, so that the values are not available in loop. The global declarations for value1 and value2 should be declared volatile, along with caution in using those variables since receiveEvent is an interrupt handler. The other major problem is that the OP sends the lower byte followed by the upper byte, then on receive throws away the lower byte by shifting it 8 bits right, and then never shifts the upper byte the required 8 bits left.