send serial only when active?


    Nov 27 2012 | 12:42 pm
    Hi
    I posted on the Arduino forum:
    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

    • Nov 27 2012 | 2:15 pm
      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
    • Nov 27 2012 | 2:44 pm
      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