I have an I2C setup between two Arduino's and everything is working fine. My ReceiveEvent reads the first byte then does a switch statement on it. Everything works fine except for one of my switch cases which contains this for loop:
for (int i = 0; i < 5; i++)
{
digitalWrite(10, LOW);
delay(250);
digitalWrite(10, HIGH);
}
I just wanted to blink the LED when a certain command is received, however it cases the I2C connection to fail and locks up my code. If I comment out that loop, it works fine. Am I missing something obvious in that loop and/or are there certain things you have to avoid in the receiveEvent?
I have an I2C setup between two Arduino's and everything is working fine. My ReceiveEvent reads the first byte then does a switch statement on it. Everything works fine except for one of my switch cases which contains this for loop:
Code:
for (int i = 0; i < 5; i++)
{
digitalWrite(10, LOW);
delay(250);
digitalWrite(10, HIGH);
}
I just wanted to blink the LED when a certain command is received, however it cases the I2C connection to fail and locks up my code. If I comment out that loop, it works fine. Am I missing something obvious in that loop and/or are there certain things you have to avoid in the receiveEvent?
Greetings. The only possibilities that I can think of for your trouble are, 1) Pin 10 is a PWM channel and can't be used a digital output, or 2) You did not initialize pin 10 as a digital output, before you tried using pin 10 as an output.
I actually have the second delay in there, I removed it by accident when I pasted the code (I removed a comment block and that line with it). The blinking isn't the problem, it's the code locking up the device. I imagine it's the delay as was mentioned by jluciani, but I haven't had a chance to confirm it.