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);
}