#include //Xiao adress will be 0x8B //Attiny adress will be 0x4A #define button D1 #define led D7 const int info = 5; int ledtimes = 0; int val = 0; bool butstate = 0; void setup() { Wire.begin(); Serial.begin(9600); pinMode(button,INPUT); pinMode(led,OUTPUT); Serial.println("I2C communication"); } void loop() { Serial.println("------------------------"); Serial.println("Press a button to start"); while (!butstate){ butstate = digitalRead(button); digitalWrite(led,HIGH); delay(100); butstate = digitalRead(button); digitalWrite(led,LOW); delay(100); ledtimes ++; } butstate = 0; Serial.println("Potenciometer"); Wire.requestFrom(0x4A, info); //Attiny, amount of information for(int i=0;i<4;i++){ char d1 = Wire.read(); Serial.print(d1); } int c = Wire.read(); // receive a byte as number val = c; Serial.println(c); Serial.print("Led blinked: "); Serial.println(ledtimes); delay(500); encrypt(val); } void encrypt(int x){ char data = 'X'; if (x < 40) { data = 'B'; } else if (x < 80){ data = 'C'; } else if (x < 120){ data = 'D'; } else if (x < 160){ data = 'E'; } else if (x < 200){ data = 'F'; } else{ data = 'A'; } Wire.beginTransmission(0x8B); Wire.write(data); // Send the byte byte error = Wire.endTransmission(); if (error == 0) { Serial.println("Transmission successful"); } else { Serial.print("Error: "); Serial.println(error); } }