//original code by Luis Diaz

//Fab Academy 2022

//Fab Lab León

//ATtiny412 control I2C

#include <Wire.h>

int i = 0;

int j = 0;

int led = 4; //led pin

void setup() {

  Serial.begin(115200); //speed of the communications

  //Begin Communication, no need for any address because this is the control

  Wire.begin();

  pinMode(led, OUTPUT); // led

}

void loop()

{

  for (i = 0; i <= 3; i++) { // 0,1,2,3

    Wire.beginTransmission(1); //node number 1

    if ( i == 1) {

      Wire.write(1);

      Serial.println("1");

    } else {

      Wire.write(0);

      Serial.println("0");

    }

    Wire.endTransmission();

    Wire.beginTransmission(2); //node number 2

    if ( i == 2) {

      Wire.write(1);

      Serial.println("1");

    } else {

      Wire.write(0);

      Serial.println("0");

    }

    Wire.endTransmission();

    for (j = 0; j <= i; j++) { // blink i times

      digitalWrite(led, HIGH);

      delay(200);

      digitalWrite(led, LOW);

      delay(200);

    }

    delay(1000);

  }

}