ArduinoArduino UnoExact chip

Two Unos over I2C

Board 1 is the I2C controller (Wire.begin()), board 2 a target at address 8 (Wire.begin(8)). Board 1 sends its knob ten times a second; board 2 sets its LED to it and answers how many it has had.

Two Unos over I2C in Argynix Lab

The code

sketch.inoC++
// Board 1, the I2C controller: sends the knob on A0 to board 2 (address 8) ten times a
// second, and asks it how many levels it has had.
#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin();  // no address: the controller
}

void loop() {
  byte level = analogRead(A0) / 4;
  Wire.beginTransmission(8);
  Wire.write(level);
  byte status = Wire.endTransmission();  // 0: board 2 took it
  Wire.requestFrom(8, 2);
  unsigned int low = Wire.read();
  unsigned int high = Wire.read();
  Serial.print("knob ");
  Serial.print(level);
  Serial.print(status == 0 ? ", board 2 has had " : ", board 2 did not answer, ");
  Serial.println(low | (high << 8));
  delay(100);
}