//original code by Luis Diaz

//Fab Academy 2022

//Fab Lab León

//ATtiny412 node 1 I2C

#include <Wire.h>

int d1 = 0;

#define led 4

void setup() {

  pinMode(led, OUTPUT);

  Serial.begin(115200);

  Wire.begin(8);     //change address for the nodes in my case I use 8 and 9.

  Wire.onReceive(recieveEvent);

}

void loop() {

  if (d1 == 1)

  {

    digitalWrite(led, HIGH);

  }

  else

  {

    digitalWrite(led, LOW);

  }

  delay(500);

}

void recieveEvent(int howMany)

{

  while (Wire.available())

  {

    d1 = Wire.read();

  }

}