Hi all,
I am trying to use the master device to command the slave to vary the blinky speed. However, I did not observe the blinky LED lighting up at all. Can someone help me look at my code to see what is wrong? Many thanks.
master device
void loop()
{
if (Serial.available() > 0) {
x = Serial.read();
Wire.beginTransmission(4); // transmit to device #4
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
}
delay(500);
}
slave device
[tr][td]
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
switch(x){
case 49:
a=500;
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(a); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(a);
break;
case 50:
a=1000;
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(a); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(a);
break;
}
}