Send pot value from slave to master and control pwm in master device

I'm beginner in arduino. I have tried for a long time But I can't find any solution. How can i send pot value from slave to master?
Can anyone please help me.
My code is given below....
this code work properly work in #Tinkercad but not work when i simulate in protius..

// Master
#include<Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
pinMode(6, OUTPUT);
}

void loop()
{
Wire.requestFrom(8,1);
byte MasterReceive = Wire.read();

analogWrite(6, MasterReceive); //
}

// Slave
#include<Wire.h>

void setup()
{
Serial.begin(9600);
Wire.begin(8);
Wire.onRequest(requestEvent);
}

void loop(void)
{

}

void requestEvent()
{
int potvalue = analogRead(A0);
byte SlaveSend = map(potvalue ,0, 1023, 0, 255);
Wire.write(SlaveSend);
}

What happens when you try it on real hardware?

Why are you not waiting until there is data in the buffer?

master Always receive 255 value, i'm increase and decrease pot but value not change.
please give me a solution.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.