So ganz verstehe ich nicht, was Du vorhast, aber ich hätte einen ausbaufähigen Vorschlag:
Du drückst TasterTor1auf beim Master und der Ausgang LEDTor1auf geht für 4 Sekunden an.
Du drückst TasterTor1zu beim Master und der Ausgang LEDTor1zu geht für 4 Sekunden an.
Master:
// Master
#include <Wire.h> //I2C-Bibliothek
#define SlaveAdresse 9 // Slave Adresse
const byte TasterTor1auf = A0;
const byte TasterTor1zu = A1;
byte a = 0;
void setup()
{
Wire.begin(); // Start the I2C Bus as Master
pinMode(TasterTor1auf, INPUT_PULLUP);
pinMode(TasterTor1zu, INPUT_PULLUP);
}
void loop()
{
if(digitalRead(TasterTor1auf))
{
a=1;
}
if(digitalRead(TasterTor1zu))
{
a=2;
}
if(a!=0)
{
Wire.beginTransmission(SlaveAdresse);
Wire.write(a);
Wire.endTransmission();
a=0;
}
}
Slave:
// Slave
#include <Wire.h>
#define SlaveAdresse 9 // Slave Adresse
#define LAUFZEIT 4000
const byte LEDTor1auf = 12;
const byte LEDTor1zu = 13;
byte a = 0;
uint32_t altMillis, laufzeit;
void setup()
{
pinMode (LEDTor1auf, OUTPUT);
pinMode (LEDTor1zu, OUTPUT);
Wire.begin(SlaveAdresse); // Start the I2C Bus as Slave
Wire.onReceive(receiveEvent); // Attach a function to trigger when something is received.
}
void receiveEvent(int bytes)
{
a = Wire.read(); // read one character from the I2C
}
void loop()
{
if (millis() - altMillis >= laufzeit)
{
altMillis = millis();
if (a == 0)
{
digitalWrite(LEDTor1zu, LOW);
digitalWrite(LEDTor1auf, LOW);
laufzeit = 0;
}
if (a == 1)
{
digitalWrite(LEDTor1auf, HIGH);
laufzeit = LAUFZEIT;
a = 0;
}
if (a == 2)
{
digitalWrite(LEDTor1zu, HIGH);
laufzeit = LAUFZEIT;
a = 0;
}
}
}
Ich hoffe, Du wirst zu eigener Kreativität angeregt