Hi community !
Sorry for my broken language, I'm French
I try to detect when there is no data which pass via Serial.
First, I think to do it like this :
void setup () {
Serial.begin(9600);
};
void loop () {
if ( Serial.available() > 0 ) {
Serial.println ( "+" );
} else {
Serial.println ( "-" );
}
}
When I begin to transfer data from PureData by Serial. It works :
When data are send, Serial print some '+', and when there is nothing to send, it prints '-'.
But, if I change the program like this, and replace the Serial print by the switching light of a LED, to avoid interferences.
#define ledPin 13;
void setup () {
Serial.begin(9600);
pinMode ( ledPin, OUTPUT );
};
void loop () {
if ( Serial.available() > 0 ) {
int bytes = Serial.read();
digitalWrite ( ledPin, HIGH );
} else {
digitalWrite ( ledPin, LOW );
}
}
If I open a Serial communication with PureData and begin to send data, the Led brights, but if I stop the Communication or when there is no data send, the LED do not shutdown... So, why ?
I certainly use a bad way, but I don't found some documentation about it...
My goal is to fetch data from PureData by Serial, to sync the luminosity of leds with sound ; and, when there is no data send from Pure data, throw a function.
I'm confused.
So if anybody can help me....
Thank you.
kny.