Hi i am new to arduino software and i had a hard time having the arduino mega 2560 to communicate
i have use these code to communicate between the arduino mega 2560 however there the LED does not seem to light up.i have taken this code from Arduino Tutorial #10: Arduino to Arduino I2C - YouTube
master code
[#include <Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
while(Serial.available())
{
char c = Serial.read();
if(c == 'H')
{
Wire.beginTransmission(5);
Wire.write('H');
Wire.endTransmission();
}
else if(c == 'L')
{
Wire.beginTransmission(5);
Wire.write('L');
Wire.endTransmission();
}
}
}]
slave
[//i2c Slave Code
#include <Wire.h>
void setup()
{
Wire.begin(5);
Wire.onReceive(receiveEvent);
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
}
void loop()
{
}
void receiveEvent(int howMany)
{
while(Wire.available())
{
char c = Wire.read();
if(c == 'H')
{
digitalWrite(13,HIGH);
}
else if(c == 'L')
{
digitalWrite(13,LOW);
}
}
}]