Skip to main content
2 of 2
added 1 character in body
Mikael Patel
  • 8k
  • 2
  • 16
  • 21

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!

Mikael Patel
  • 8k
  • 2
  • 16
  • 21