Hello, I am trying to send a variable resistor's input from one Arduino to another (wirelessly using Xbee modules). The second Arduino will vary the brightness of an LED depending on the value of the variable resistor.
Everything is working but there is about a 1 second delay before the LED responds to the change of the variable resistor.
Here is my code:
Sender:
// SENDER
int analogValue5, val5;
void setup()
{Serial.begin(9600);}
void loop()
{
analogValue5 = analogRead(5);
val5 = map(analogValue5, 0, 1023, 255, 0);
Serial.write(val5);
delay(300);
}
Receiver:
// RECIEVER
int incomingByte;
void setup() {
Serial.begin(9600);
pinMode (11, OUTPUT);
}
void loop() {
if (Serial.available()) {
incomingByte = Serial.read();
delay(300);
}
analogWrite (11, incomingByte);
delay(10);
}
Anyone knows how I can reduce or eliminate this delay?