I am using serial.write to send data from 12 diy FSR's - to MaxMSP - and I recently learned from a more experienced colleague that it is common practice to send data only when it changes. This sounds attractive. Would it simply be a matter of writing the following:
int var=analogRead(myPin);
if (var > 0){
Serial.write (var);
}
else
{
//do nothing
}
Will this 'mute' or clear the serial buffer when my sensors are inactive? I guess my question is, how do I send my data only when the sensors are sending values > 0?
Yes, I tried my own example and my 'sent' data is unreliable. As my FSRs are homemade, the raw values fluctuate from c.120 (+/-5) to c. 800 (+/-5) so I was using [map] and [constrain] quite heavily to force the inactive value down to zero. Could I ask for further help in applying a delta function; this way I can send data only when the delta exceeds a set threshold.
This will send a value only when the difference between the current value and the previous value is greater than 5, positive or negative.
You might want to divide the fsr reading by some amount, say 5, and then send each (different) value without worrying about a range. Either one will work.