send serial only when active?

Nov 27, 2012 at 12:42pm

send serial only when active?

Hi
I posted on the Arduino forum:

http://arduino.cc/forum/index.php/topic,134478.0.html

and to cover all the bases, I’m selfishly asking here too. I’m in the process of optimizing a Max/Arduino tool which features 18 FSRs and 18 LEDs, kind of a DIY QuNeo/Monome thing. My simple question is this: how can I ensure that the Arduino is sending serial data only when the sensors are active, >0., or changing. Is it simply a matter of:

if (myVar>0.){
Serial.write(myVar);
}
else{
//do nothing
}

I’ll go off and have a wee noodle with my code now anyway and see what happens,
Cheers

Brendan

#65381
Nov 27, 2012 at 2:15pm

yeah, that’s not gonna do it. It works, but unreliably, mainly as I’m using diy sensors.

Update:

how would I write a delta function in Arduino? Read sensor; read again, subtract current from previous; if delta >myThreshold then send, else flush and do nothing.

Said as much on the Duino forum too

#235592
Nov 27, 2012 at 2:44pm

Success, as follows IAI (my own new acronym: “if anyone’s interested”):

int currVal;
int prevVal;
int delta;

void loop(){
currVal=analogRead(0);
delta=currVal-prevVal;
prevVal=currVal;
}

there’s other stuff going one, but not relevant to delta acquisition.

Once again, apologies for the [noise~]

Brendan

#235593

You must be logged in to reply to this topic.