//Master// #include #include #define SLAVE_ADDR 8 LiquidCrystal lcd(3,4,5,6,7,8); int volume; void setup() { Wire.begin(); Serial.begin(115200); lcd.begin(16, 2); lcd.clear(); lcd.print("Volume:"); lcd.setCursor(0,1); } void loop() { delay(2000); int16_t vol; byte a,b; Wire.requestFrom(8,2); a = Wire.read(); // receive a byte as character b = Wire.read(); volume = a; volume = (volume<<8)|b; lcd.setCursor(1,1); lcd.print(vol); lcd.print(" %"); Serial.println(vol); // print the character lcd.write(1); } //Slave// #include #define pulse_ip 9 #define SLAVE_ADDR 8 int ontime,offtime,volume,Fdiff; float freq,period,temp,adc_val; int Fmin = 6000; int Fmax = 9100; void setup(){ pinMode(pulse_ip,INPUT); Wire.begin(8); // join i2c bus with address #8 Wire.onRequest(requestEvent); // register event } void loop(){ delay(100); } void requestEvent(){ ontime = pulseIn(pulse_ip,HIGH); offtime = pulseIn(pulse_ip,LOW); period = ontime+offtime; freq = 1000000.0/period; if(period==0){ freq=0; } adc_val=analogRead(A1); // temperature readings temp=(adc_val4.85)/10; Fdiff = Fmax - Fmin; volume = ((Fmax-freq)/Fdiff)*100; int16_t vol = volume; byte myArray[2]; myArray[0] = (vol>>8)& 0xFF; myArray[1] = vol & 0xFF; Wire.write(myArray,2); delay(200); }