by means of a push button on the master, the master should give a command to one of the slaves, which should make a pin high or low on a slave ( mega or uno )
maybe, i can find out by myself, to what slave the master will send the commando.
this is the sketch for the slave
type or paste code here
/*
I2C Slave Control Demo
i2c-slave-demo-control.ino
Demonstrate use of I2C bus
Receives potentimeter position data
Controls LED blink rate
DroneBot Workshop 2019
https://dronebotworkshop.com
*/
// Include Arduino Wire library for I2C
#include <Wire.h>
// Define Slave I2C Address
#define SLAVE_ADDR 8
// Define LED Pin
int LED = 13;
// Variable for received data
int rd;
// Variable for blink rate
int br;
void setup() {
pinMode(LED, OUTPUT);
// Initialize I2C communications as Slave
Wire.begin(SLAVE_ADDR);
// Function to run when data received from master
Wire.onReceive(receiveEvent);
// Setup Serial Monitor
Serial.begin(9600);
Serial.println("I2C Slave Demonstration");
}
void receiveEvent() {
// read one character from the I2C
rd = Wire.read();
// Print value of incoming data
Serial.println(rd);
}
void loop() {
delay(50);
// Calculate blink value
br = map(rd, 1, 255, 100, 2000);
digitalWrite(LED, HIGH);
delay(br);
digitalWrite(LED, LOW);
delay(br);
}
> Blockquote
this for the master
Blockquote
/*
I2C Master Control Demo
i2c-master-demo-control.ino
Demonstrate use of I2C bus
Master sends potentimeter position data
DroneBot Workshop 2019
https://dronebotworkshop.com
*/
// Include Arduino Wire library for I2C
#include <Wire.h>
// Define Slave I2C Address
#define SLAVE_ADDR 8
// Analog pin for potentiometer
int analogPin = 0;
// Integer to hold potentiometer value
int val = 0;
void setup() {
// Initialize I2C communications as Master
Wire.begin();
}
void loop() {
delay(50);
// Read pot value
// Map to range of 1-255 for flash rate
val = map(analogRead(analogPin), 0, 1023, 255, 1);
// Write a charatre to the Slave
Wire.beginTransmission(SLAVE_ADDR);
Wire.write(val);
Wire.endTransmission();
}
Blockquote
`