29 lines
482 B
C++
29 lines
482 B
C++
#include <Arduino.h>
|
|
#include <Wire.h>
|
|
|
|
#define SDA_PIN 21
|
|
#define SCL_PIN 22
|
|
|
|
#define SLAVE_ADDRESS 0x0B
|
|
|
|
void requestEvent();
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
|
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
|
|
|
Wire.onRequest(requestEvent);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
}
|
|
|
|
void requestEvent()
|
|
{
|
|
// TODO: Send data to the master when requested
|
|
Serial.println("Master requested data from Slave.");
|
|
Wire.write("Hello from Slave!");
|
|
} |