arduino, sensor box and a button

    MaxMSP

    mantaraffu's icon
    mantaraffu's icon
    mantaraffu
    Jun 22 2011 | 11:18 am
    Hi, I'm looking for a realize a simple series of button to launch samples using arduino and sensor box. the problem is that everytime I push the button, obviously arduino send a fast sequence of 0 and 1, so my sample start and stop. when I push a button, I need only one 1, not a series of 1 and 0. any suggestion?

    • Jan's icon
      Jan's icon
      Jan
      Jun 22 2011 | 11:58 am
      [change] is your friend ;)
      Share
    • mantaraffu's icon
      mantaraffu's icon
      mantaraffu
      Jun 22 2011 | 12:32 pm
      you rock! thank you
    • Jan's icon
      Jan's icon
      Jan
      Jun 22 2011 | 12:43 pm
      Thanx! ;)
      Another way would be to alter your Arduino script in that way that you only print to the serial port if the value has changed.
      int oldButtonState = 0; int buttonState = 0; [...] void loop() { buttonState = digitalRead(); if (oldButtonState != buttonState { Serial.write(buttonState); oldButtonState = buttonState; } }
      [this is untested just dirty coding to explain the mechanism]
      It will have the same effect at then but be slightly more elegant, as you avoid unnecessary data transfer.
      Jan
    • mantaraffu's icon
      mantaraffu's icon
      mantaraffu
      Jun 22 2011 | 5:01 pm
      you right, and I'm a bit lazy on arduino programming. I'm building a simple system, maybe with time I will build a similar system using only arduino, I'm trying this code on sensor box...