// CPU: 80 MHz, v2 Lower Memory //
#include <Wire.h>
#define SLAVE_ADDRESS 0x60
#define I2C_BUFFER_LENGTH 256
//struct OUT from slave to master
typedef struct {
signed short int int_1 = 0;
signed short int int_2 = 0;
  signed short int int_3 = 0;
  signed short int int_4 = 0;
  signed short int int_5 = 0;
  signed short int int_6 = 0;
  signed short int int_7 = 0;
signed short int int_8 = 0;
signed short int int_9 = 0;
  signed short int int_10 = 0;
  signed short int int_11 = 0;
  signed short int int_12 = 0;
  signed short int int_13 = 0;
  }
B_t;
B_t my_struct2;
const int led = D4;
 String hello;
volatile boolean merhet = 0;
//if(strcmp(corpo, "123") == 0) { }  // ha a char corpo == 123
/////////////////////////////////////////////////////////////////////////
void setup(){
  Wire.begin(SLAVE_ADDRESS);
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);
  pinMode(led, OUTPUT); digitalWrite(led, HIGH);
  Serial.begin(115200);Serial.println();Serial.println();Serial.println("indul ...");
my_struct2.int_1 = 0;
my_struct2.int_2 = -10;
my_struct2.int_3 = 0;
my_struct2.int_4 = 0;
my_struct2.int_5 = 0;
my_struct2.int_6 = 0;
my_struct2.int_7 = 0;
my_struct2.int_8 = 0;
my_struct2.int_9 = 0;
my_struct2.int_10 = -10;
my_struct2.int_11 = -10;
my_struct2.int_12 = 10;
my_struct2.int_13 = 10;

}
////////////////////////////////////////////////////////////////////////
void loop(){ 
 if(merhet == 1){  merhet = 0; 
my_struct2.int_1 += 11;  if(my_struct2.int_1 > 10000){ my_struct2.int_1 = 0; }
my_struct2.int_2 += 1;   if(my_struct2.int_2 > 10000){ my_struct2.int_2 = 0; }
my_struct2.int_3 += 1;   if(my_struct2.int_3 > 10000){ my_struct2.int_3 = 0; }
my_struct2.int_4 += 1;   if(my_struct2.int_4 > 10000){ my_struct2.int_4 = 0; }
my_struct2.int_5 += 1;   if(my_struct2.int_5 > 10000){ my_struct2.int_5 = 0; }
my_struct2.int_6 += 1;   if(my_struct2.int_6 > 10000){ my_struct2.int_6 = 0; }
my_struct2.int_7 += 1;   if(my_struct2.int_7 > 10000){ my_struct2.int_7 = 0; }
my_struct2.int_8 += 1;   if(my_struct2.int_8 > 10000){ my_struct2.int_8 = 0; }
my_struct2.int_9 += 1;   if(my_struct2.int_9 > 10000){ my_struct2.int_9 = 0; }
my_struct2.int_10 += 1;  if(my_struct2.int_10 > 10000){  my_struct2.int_10 = 0; }
my_struct2.int_11 += 1;  if(my_struct2.int_11 > 10000){  my_struct2.int_11 = 0; }
my_struct2.int_12 -= 1;  if(my_struct2.int_12 < -10000){ my_struct2.int_12 = 0; }
my_struct2.int_13 -= 1;  if(my_struct2.int_13 < -10000){ my_struct2.int_13 = 0; }
//my_struct2.int_14 += 1;
  } }
//////////////////////////////////////////////////
// function that executes whenever data is requested from master
void requestEvent() {  digitalWrite(led, HIGH);
 if(hello == "hello"){
 Wire.write((byte *)&my_struct2, sizeof my_struct2); } /*send string on request */
 hello = "";
 merhet = 1; }

/////////////////////////////////////////////////
// function that executes whenever data is received from master
void receiveEvent(int howMany) {
  digitalWrite(led, LOW);
 while (0 < Wire.available()) {
    char c = Wire.read();      // receive byte as a character 
    hello += c;
  } 
 Serial.print("keres:"); Serial.print(hello); Serial.print(".");
 Serial.println();            

}
