I have this code:
int data=0;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.write(data);
delay(50);
}
void serialEvent() {
data = Serial.read();
}
This example should update the data variable when serial data is received. But for some reason it does not work that way, nothing gets printed in the serial monitor.
But when I move the Write method to serialEvent function, I have my data printed as expected. Why is this happening? If I'm correct, the data variable should be printed with the last value I got from Serial.read().
main()than be of actual use. \$\endgroup\$