user28862: I'm trying to make a game where i can use one Arduino as a controller (the controller is a potentiometer) and the other Arduino sending the signals to the computer. Im trying to figure out communication with two Arduino's so i would like to use two instead of one although using one would be logical and easier. Ive tried looking into I2C but cant seem to figure it out.

user13432: Start by reading the potentiometer. Add a Wire request service function and that makes the Slave:
#include <Wire.h>

const uint8_t controllerAddress = 8;
const int controllerPin = A0;
volatile int controllerValue = 0;

void setup() {
  Wire.begin(controllerAddress);
  Wire.onRequest(requestEvent); 
}

void loop() {
  int value = analogRead(controllerPin);
  noInterrupts(); 
    controllerValue = value;  
  interrupts();
}

void requestEvent() {
  Wire.write((const uint8_t*) &controllerValue, sizeof(controllerValue)); 
}

This is minor update of the Arduino Wire Master Reader tutorial. The sketch for the Master is left as an exercise. 
Cheers!

28862: <p>I'm trying to make a game where i can use one Arduino as a controller (the controller is a potentiometer) and the other Arduino sending the signals to the computer. Im trying to figure out communication with two Arduino's so i would like to use two instead of one although using one would be logical and easier. Ive tried looking into I2C but cant seem to figure it out.</p>
 13432: <p>Start by reading the potentiometer. Add a Wire <a href="https://www.arduino.cc/en/Reference/WireOnRequest" rel="nofollow noreferrer">request service function</a> and that makes the Slave:</p>

<pre><code>#include &lt;Wire.h&gt;

const uint8_t controllerAddress = 8;
const int controllerPin = A0;
volatile int controllerValue = 0;

void setup() {
  Wire.begin(controllerAddress);
  Wire.onRequest(requestEvent); 
}

void loop() {
  int value = analogRead(controllerPin);
  noInterrupts(); 
    controllerValue = value;  
  interrupts();
}

void requestEvent() {
  Wire.write((const uint8_t*) &amp;controllerValue, sizeof(controllerValue)); 
}
</code></pre>

<p>This is minor update of the <a href="https://www.arduino.cc/en/Tutorial/MasterReader" rel="nofollow noreferrer">Arduino Wire Master Reader</a> tutorial. The sketch for the Master is left as an exercise. </p>

<p>Cheers!</p>
