Hi,
I am trying to write a simple i2c reader and when i come to compile the code i get an error " argument of type “void()()" is incompatible with parameter of type "void()(int)”
code is below, the error relates to line Wire.onReceive(read_data);
any help would be greatly appreciated.
#include <Wire.h>
// Define Slave I2C Address
#define SLAVE_ADDR 9
// Variable for received data
int rd;
// Variable for blink rate
int br;
void setup() {
// Initialize I2C communications as Slave
Wire.begin(SLAVE_ADDR);
// Function to run when data received from master
Wire.onReceive(read_data);
// Setup Serial Monitor
Serial.begin(9600);
Serial.println("I2C Slave Demonstration");
}
void loop() {
delay(50);
rd = Wire.read();
Serial.println(rd);
// Calculate blink value
br = map(rd, 1, 255, 10, 100);
}
void read_data() {
// read one character from the I2C
rd = Wire.read();
// Print value of incoming data
Serial.println(rd);
}